function solution(survey, choices) {
const types = [['R', 'T'], ['C', 'F'], ['J', 'M'], ['A', 'N']]
const scores = { 1:3, 2:2, 3:1, 4:0, 5:1, 6:2, 7:3 }
let result = {}
let answer = ''
// 설문을 통한 각 type 에 대한 점수
survey.forEach((sv, idx) => {
const first = sv.charAt(0)
const second = sv.charAt(1)
if (choices[idx] < 4) {
result[first] = (result[first] || 0) + scores[choices[idx]]
} else if (choices[idx] > 4) {
result[second] = (result[second] || 0) + scores[choices[idx]]
} else {
}
})
// 점수 > 순서로 최종 type 뽑아내기
types.forEach((type, idx) => {
const score_of_first = result[type[0]] || 0;
const score_of_second = result[type[1]] || 0;
if (score_of_first === 0 && score_of_second === 0) {
answer += type[0];
} else {
answer += (score_of_first >= score_of_second ? type[0] : type[1]);
}
})
return answer;
}
function solution(survey, choices) {
const MBTI = {};
const types = ["RT","CF","JM","AN"];
types.forEach((type) =>
type.split('').forEach((char) => MBTI[char] = 0)
)
choices.forEach((choice, index) => {
const [disagree, agree] = survey[index];
MBTI[choice > 4 ? agree : disagree] += Math.abs(choice - 4);
});
return types.map(([a, b]) => MBTI[b] > MBTI[a] ? b : a).join("");
}