https://school.programmers.co.kr/learn/courses/30/lessons/42840

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

 

function solution(answers) {
  var answer = [];
  var ansMap = new Map();
  ansMap.set(1, 0);
  ansMap.set(2, 0);
  ansMap.set(3, 0);

  var one = [1, 2, 3, 4, 5];
  var two = [2, 1, 2, 3, 2, 4, 2, 5];
  var three = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
  var myAnswer = [one, two, three];

  answers.forEach((a, idx) => {
    myAnswer.forEach((m, num) => {
      if (a === m[idx % m.length]) {
        ansMap.set(num + 1, ansMap.get(num + 1) + 1);
      }
    });
  });

  let res = [ansMap.get(1), ansMap.get(2), ansMap.get(3)];

  function findMaxIndices(arr) {
    if (arr.length === 0) {
      return [];
    }

    const maxValue = Math.max(...arr);

    const maxIndices = arr
      .map((value, index) => (value === maxValue ? index + 1 : -1))
      .filter(index => index !== -1);

    return maxIndices;
  }

  return findMaxIndices(res);
}

먼가 구질구질하게 푼 것 같지만...일단풀었다 ㅎㅎ 

+ Recent posts