프로그래머스 - 성격 유형 검사하기
part21. 성격 유형 검사하기
js ver 1.0
function solution(survey, choices) {
let answer = "";
const obj = {R: 0, C: 0, J: 0, A: 0, T: 0, F: 0, M: 0, N: 0}
survey.forEach((el, idx) => {
const [l, r] = [...el];
if(choices[idx] < 4){
obj[l] += Math.abs(choices[idx] - 4);
}else{
obj[r] += choices[idx] - 4;
}
});
const type = Object.keys(obj);
for (let i = 0; i < type.length / 2; i++) {
const l = obj[type[i]];
const r = obj[type[i + 4]];
if (l < r) {
answer += type[i + 4];
} else {
answer += type[i];
}
}
return answer;
}