[JS] 프로그래머스 0단계: 정답률 71% - 외계어 사전

ahyes·2022년 12월 11일
0
post-thumbnail

안녕하세요.
11월 목표였던 0단계를 끝마치지는 못했네요..
그래도 힘내서 문제를 풀어봅시다.

정답률 71% 외계어 사전 문제입니다.

function solution(spell, dic) {
    dic=dic.map(x => [...x]);
    spell.forEach(e => {
        dic.map(x => x.indexOf(e) > -1?x[x.indexOf(e)] = '':x.push('?'))
    })
    return dic.map(x => x.join('')).filter(el => el === "").length > 0?1:2;
}

(추가!!)

function solution(spell, dic) {
    return dic.map(x=>[...x].sort().join('')).includes(spell.sort().join(''))?1:2;
}
profile
티스토리로 이사갑니다. https://useyhnha.tistory.com/

0개의 댓글