Muscardinus
베스트 앨범 본문
728x90
programmers.co.kr/learn/courses/30/lessons/42579?language=javascript
function solution(genres, plays) {
const summaryGenres = genres.reduce((acc, cur, index) => {
if (!acc[cur]) {
acc[cur] = {
totalPlay: 0,
playList: []
};
}
acc[cur].totalPlay += plays[index];
acc[cur].playList.push([index, plays[index]]);
return acc;
}, {});
const summaryGenresList = Object.values(summaryGenres).sort((a, b) => b.totalPlay - a.totalPlay);
const answer = summaryGenresList.reduce((acc, cur) => {
cur.playList.sort((a,b) => b[1] - a[1]);
acc.push(cur.playList[0][0]);
if (cur.playList.length > 1) acc.push(cur.playList[1][0]);
return acc;
}, []);
return answer;
}
728x90
Comments