[Lv.0] 외계어 사전

01수정·2023년 6월 7일
0
post-thumbnail

<입문 100문제> Day 21 - 문자열, 사칙연산, 시뮬레이션, 2차원배열, 수학, 배열

문제



풀이

function solution(spell, dic) {
    let answer = [];
    let counter = 0;

    dic.forEach(item => {
        for (let i=0; i<spell.length; i++) {
            if (item.includes(spell[i])) {
                counter += 1;
            }
        }
        if (counter >= spell.length) {
            answer.push(item);
        }
        counter = 0;
    });
    
    return answer.length > 0 ? 1 : 2;
}

해답

profile
새싹 FE 개발자

0개의 댓글