솔루션
const solution = (spell, dic) => {
const sort = (str) =>
[...str].sort((a, b) => (a < b ? -1 : a !== b ? 1 : 0)).join("");
const answer = dic.find((dic) => sort(dic) === sort(spell.join(""))) ? 1 : 2;
console.log(answer);
return answer;
};
solution(["p", "o", "s"], ["sod", "eocd", "qixm", "adio", "soo"]);
solution(["z", "d", "x"], ["def", "dww", "dzx", "loveaw"]);
solution(["s", "o", "m", "d"], ["moos", "dzx", "smm", "sunmmo", "som"]);
'프로그래머스(Javascript) > Level 0' 카테고리의 다른 글
[프로그래머스 | 자바스크립트] 안전지대 (0) | 2023.04.16 |
---|---|
[프로그래머스 | 자바스크립트] 삼각형의 완성조건(2) (0) | 2023.03.11 |
[프로그래머스 | 자바스크립트] 저주의 숫자 3 (0) | 2023.03.03 |
[프로그래머스 | 자바스크립트] 평행 (0) | 2023.03.03 |
[프로그래머스 | 자바스크립트] 겹치는 선분의 길이 (0) | 2023.03.02 |