[프로그래머스] 성격 유형 검사하기

최유나·2024년 10월 13일
0

프로그래머스

목록 보기
50/53

✨ 성격 유형 검사하기

나의 풀이

function solution(survey, choices) {
     const 스코어들 = {
        R: 0, T: 0,
        C: 0, F: 0,
        J: 0, M: 0,
        A: 0, N: 0,
    }
    
    // 테스트지 점수
    choices.forEach((choice, idx) => {
        const [비동의, 동의] = survey[idx]
        // 비동의 점수 더하기
        if(choice < 4) 스코어들[비동의] += (4 - choice);
        // 동의 점수 더하기
        if(choice > 4) 스코어들[동의] += (choice -4)
    });
    
    const result = [
        스코어들.R >= 스코어들.T ? 'R':'T',
        스코어들.C >= 스코어들.F ? 'C':'F',
        스코어들.J >= 스코어들.M ? 'J':'M',
        스코어들.A >= 스코어들.N ? 'A':'N'
    ].join('')

    return result;
}

mbti페이지를 만들 때 사용 했던 로직과 비슷하게 풀이 함

다른사람의 풀이

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("");
}

0개의 댓글

관련 채용 정보