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));
- Change
i < endtoi <= end - Change
i = starttoi = start - 1 - Change
out.push(i)toout.push(i + 1) - Change
range(1, 5)torange(1, 4)
To include
Play Problem Solving ▸
end, the loop condition must be i <= end.