$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #49

Which fix removes the bug?

function range(start, end) {
  const out = [];
  for (let i = start; i < end; i++) out.push(i);
  return out;
}
console.log(range(1, 5).includes(5));
  1. Change i < end to i <= end
  2. Change i = start to i = start - 1
  3. Change out.push(i) to out.push(i + 1)
  4. Change range(1, 5) to range(1, 4)
To include end, the loop condition must be i <= end.
Play Problem Solving ▸