프로그래머스 위클리 챌린지 4주차 - 직업군 추천하기 [ javascript ]

프로그래머스 위클리 챌린지 4주차 - 직업군 추천하기 [ javascript ]

반응형

정렬을 위한 데이터를 뽑아내고 조건에 맞게 정렬하였습니다.

const solution = (table, languages, preference) => { return table .map(r => { const row = r.split(" ").reverse(); const name = row.pop(); const score = languages.reduce( (acc, language, idx) => (acc += (row.indexOf(language) + 1) * preference[idx]), -1 ); return { name, score }; }) .sort((a, b) => (a.name > b.name ? 1 : -1)) .reduce( (answer, next) => (answer = answer.score < next.score ? next : answer), { score: 0 } ).name; };

반응형

from http://dalconbox.tistory.com/291 by ccl(S) rewrite - 2021-09-11 05:27:24