function solution(survey, choices) {
const test = {};
for (var i = 0; i < survey.length; i++) {
if (choices[i] < 4) {
if (test[survey[i][0]] == undefined) {
test[survey[i][0]] = 4-choices[i];
}
else{
test[survey[i][0]] += 4-choices[i];
}
}
else if (choices[i] > 4) {
if (test[survey[i][1]] == undefined) {
test[survey[i][1]] = choices[i]-4;
}
else{
test[survey[i][1]] += choices[i]-4;
}
}
}
var answer = "";
const mbtiList = ['RT', 'CF', 'JM', 'AN'];
for (var i = 0; i < mbtiList.length; i++) {
if(test[mbtiList[i][0]] == undefined){
test[mbtiList[i][0]] = 0
}
if(test[mbtiList[i][1]] == undefined){
test[mbtiList[i][1]] = 0
}
if(test[mbtiList[i][0]] >= test[mbtiList[i][1]]){
answer += mbtiList[i][0]
}
else{
answer += mbtiList[i][1]
}
}
return answer;
}
console.log(solution(
["AN", "CF", "MJ", "RT", "NA"], [5, 3, 2, 7, 5]
));
더 짧게 리펙토링 할 수 있으니 다음에 까먹을 때 즈음에 한 번 더 해볼 것..!!!