2022 카카오 테크 인턴십
function solution(survey, choices) {
const typeScore = { R: 0, T: 0, C: 0, F: 0, J: 0, M: 0, A: 0, N: 0 };
const types = ['RT', 'CF', 'JM', 'AN'];
choices.forEach((choice, idx) => {
const [x, o] = survey[idx];
typeScore[choice > 4 ? o : x] += Math.abs(choice - 4);
});
return types.map(([a, b]) => typeScore[b] > typeScore[a] ? b : a).join('');
}
입력값의 제한은 다음과 같다.
이중 for문 사용까지는 무방하다고 생각했다.
✨ 한 가지 사실을 짚고 넘어가자면, 다음처럼 변수를 선언할 수 있다!
const exStr = 'ab';
const [str1, str2] = exStr;
console.log(str1); // ✅ 'a'
console.log(str2); // ✅ 'b'