๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/42840
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
function solution(answers) {
var answer = [];
var a1 = [1, 2, 3, 4, 5];
var a2 = [2, 1, 2, 3, 2, 4, 2, 5]
var a3 = [ 3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
var a1c = answers.filter((a,i)=> a === a1[i%a1.length]).length;
var a2c = answers.filter((a,i)=> a === a2[i%a2.length]).length;
var a3c = answers.filter((a,i)=> a === a3[i%a3.length]).length;
var max = Math.max(a1c,a2c,a3c);
if (a1c === max) {answer.push(1)};
if (a2c === max) {answer.push(2)};
if (a3c === max) {answer.push(3)};
return answer;
}
๋ดํ์ด๐ฝ
1. ์ฑ๊ณต โญ
function solution(answers) {
var answer = [];
let first = [1,2,3,4,5] // 5
let second = [2,1,2,3,2,4,2,5] // 8
let third = [3,3,1,1,2,2,4,4,5,5] // 10
let scoreArr = [0,0,0]
for(let i=0; i<answers.length; i++){
let answer=answers[i]
if(answer===first[(i%5)]) ++scoreArr[0]
if(answer===second[(i%8)]) ++scoreArr[1]
if(answer===third[(i%10)]) ++scoreArr[2]
}
let highestScore = Math.max(...scoreArr)
for(let i=0; i<scoreArr.length; i++){
if(highestScore===scoreArr[i]){
answer.push(i+1)
}
}
return answer;
}
๋๋์ ๐ฝ
์ด๋ ต์ง ์๊ฒ ํ ์ ์์๋ค!