Programmers Algorithm - 추억점수

Myung Jin Kim·2023년 8월 27일
0

이전에 풀었던, 달리기 경주와 비슷한 맥락의 문제여서 좀더 쉽게 풀 수 있었다.

function solution(name, yearning, photo) {
    const nameScoreObj = {}; 
    name.forEach((eachName, index) => {
        nameScoreObj[eachName] = yearning[index];
    });
    return photo.map(photoNames => {
        return photoNames.reduce((total, cur) => {
            return total + (nameScoreObj[cur] || 0);
        }, 0);
    })
}

다른 사람들의 풀이를 봤을 때도 답이 거의 비슷한 경우가 많았다.

profile
개발을 취미로 하고 싶은 개발자를 목표로 살고 있습니다

0개의 댓글