Code QuizIntermediate

Self-Consistency Voting

Find why the majority-vote aggregator returns the wrong answer.

Codejavascript
// Pick the most common answer across sampled completions
function majorityVote(answers) {
  const counts = {};
  for (const a of answers) counts[a] = (counts[a] || 0) + 1;
  return Object.keys(counts)[0];
}

majorityVote(["7", "42", "42", "42", "7"]);

What is the bug in this voting function?