Let's now turn to a helper function, which will come in handy for many uses. We want a range(start,stop) function that generates an array of numbers, with values ranging from start (inclusive) to stop (exclusive):
const range = (start, stop) => new Array(stop - start).fill(0).map((v, i) => start + i);let from2To6 = range(2, 7); // [2, 3, 4, 5, 6]
Why fill(0)? All undefined array elements are skipped by map(), so we need to fill them with something or our code will have no effect.