Problem Description
I am trying to generate an array using keys() and .map() methods, given a preexisting array with length = arrLength, such that only items at a position that are multiples of step are generated. Here is an example,
const arrLength = 20;
const step = 5;
const newArr = [...Array(arrLength).keys() ].map((i) => i + step);
console.log(newArr) ;
// expected: 0,5,10,15,20
// recieved : 5,6,7,...,24
I am particlarly confused as to how to increment the left hand side variable i in map((i) => ... ).
Restrictions
I want to implement this in one line using the keys method and Array and possibly map, so no for loop.
Things I have tried
I tried the following signatures instead
Array(arrLength).fill().map((_, i) => i+step) ,
Array.from(Array(arrLength), (_, i) => i+step),
Array.from({ length: arrLength }, (_, i) => i+step)
but with no success. I have further tried to find a way to increment the i variable using functional syntax but with no success as wel.