이전에 풀었던, 달리기 경주와 비슷한 맥락의 문제여서 좀더 쉽게 풀 수 있었다.
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);
})
}
다른 사람들의 풀이를 봤을 때도 답이 거의 비슷한 경우가 많았다.