[프로그래머스] 다른 사람의 풀이

arrrrrr·2023년 3월 23일

문제

링크

내가 푼 코드

function solution(id_pw, db) {
    let result = [];
        db.filter(el => {
        if (el[0] === id_pw[0]) { 
            result.push(el[0]);
            if (el[1] === id_pw[1]) result.push(el[1]);
        } 
    }); 
    return result.length === 2 ? "login" : result.length === 1 ? "wrong pw" : "fail" ; 
}

탐나는 코드

function solution(id_pw, db) {
  const [id, pw] = id_pw;
  const map = new Map(db);
  return map.has(id) ? (map.get(id) === pw ? 'login' : 'wrong pw') : 'fail';
}

0개의 댓글