프로그래머스 Level 1 - 성격 유형 검사하기

크롱·2024년 1월 29일
0

코딩테스트

목록 보기
60/61

내 풀이

function solution(survey, choices) {
    var answer = '';
     const type = {'R':0,'T':0,'C':0,'F':0,'J':0,'M':0,'A':0,'N':0}

     for(let i=0;i<survey.length;i++){
         if(choices[i]>4){
             type[survey[i][1]] += choices[i]-4
         }else if(choices[i]<4){
              type[survey[i][0]] += choices[i]==2?choices[i]: (choices[i]===1? 3:1)
         }
     }

    if(type['R']<type['T']){
        answer+='T'
    }else{
        answer+='R'
    }

     if(type['C']<type['F']){
        answer+='F'
    }else{
        answer+='C'
    }

      if (type['J']<type['M']) {
        answer += 'M'
    } else {
        answer += 'J'
    }
    if (type['A']<type['N']) {
        answer += 'N'
    } else {
        answer += 'A'
    }
    return answer
}
profile
👩‍💻안녕하세요🌞

0개의 댓글