1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| function solution(answers) { const a = [1, 2, 3, 4, 5]; const b = [2, 1, 2, 3, 2, 4, 2, 5]; const c = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5];
let count = [0, 0, 0]; answers.forEach((element, index) => { a[index % a.length] == element ? count[0]++ : null; b[index % b.length] == element ? count[1]++ : null; c[index % c.length] == element ? count[2]++ : null; }); let result = []; let max = Math.max.apply(null, count); count.forEach((item, idx) => { if (max == item) { result.push(idx + 1); } }); return result; } solution([1, 2, 3, 4, 5]);
|