Arrayintermediateconst range = [...new Array(4).keys()]
range // β [0, 1, 2, 3]Spread new Array(n).keys() to generate a compact 0-based index range array.
To produce [1, 2, 3, β¦, n] you can combine new Array(n) (which creates n empty slots) with Array.from and a mapping function, or spread the result of Array(n).keys().
Challenge: Implement createRange that returns [1, 2, β¦, n].
createRange(5) // β [1, 2, 3, 4, 5]
createRange(1) // β [1]