$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #136

Which fix removes the bug?

if (names.indexOf(target)) {
  console.log('found');
}
  1. Compare the result to -1
  2. Swap the arguments around
  3. Use indexOf on a copy
  4. Sort names before the check
indexOf returns 0 for the first element, which is falsy — test !== -1.
Play Problem Solving ▸