Last active
August 25, 2021 02:35
-
-
Save emayom/3085fe16afd2c27998b689b4ad512a04 to your computer and use it in GitHub Desktop.
[프로그래머스] 위클리챌린지 직업군 추천하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(table, languages, preference) { | |
const FIELD = ["SI", "CONTENTS", "HARDWARE", "PORTAL", "GAME"]; | |
const separate = []; | |
const count = []; | |
let answer = []; | |
for(let i of table){ | |
let temp = i.split(' '); | |
separate.push(temp.slice(1)); | |
} | |
const LANGUAGES = languages.length; | |
separate.map((el) => { | |
let point = 0; | |
for(let i=0; i < LANGUAGES; i++){ | |
let temp = el.indexOf(languages[i]); | |
(temp === -1)? point += 0 : point += (temp-5) * preference[i]; | |
} | |
count.push(Math.abs(point)); | |
}); | |
const MAX = Math.max(...count); | |
count.forEach((el, index) => { | |
(el === MAX)? answer.push(FIELD[index]) : ''; | |
}); | |
return answer.sort((a,b) => (a > b)? 1 : -1).shift();; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(table, languages, preference) { | |
const FIELD = ["SI", "CONTENTS", "HARDWARE", "PORTAL", "GAME"]; | |
const separate = []; | |
//table -> 직업별 분류 | |
table.map((i) => { | |
let temp = i.split(' '); | |
separate.push(temp.slice(1)); | |
}); | |
//점수 계산 (언어 선호도 x 직업군 언어 점수) | |
const count = []; | |
const LANGUAGES = languages.length; | |
separate.map((el) => { | |
let point = 0; | |
for(let i=0; i < LANGUAGES; i++){ | |
let temp = el.indexOf(languages[i]); | |
(temp === -1)? point += 0 : point += (temp-5) * preference[i]; | |
} | |
count.push(Math.abs(point)); | |
}); | |
//총합 가장 큰 직업군 -> 사전 순으로 빠른 직업군 리턴 | |
const MAX = Math.max(...count); | |
let answer = []; | |
count.map((el, index) => { | |
(el === MAX)? answer.push(FIELD[index]) : ''; | |
}); | |
return answer.sort((a,b) => (a > b)? 1 : -1).shift(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment