0

I keep writing array generation function so that I can invoke the map function on blank arrays of fixed sizes. Is there an expression I can chain a map invocation to so that I don't have to reference an array generation function from local vars?

The following code with function and for loop and all of its verbosity is what I'm trying to eradicate:

var genArray = resolution => {

  var arr = [];

  for (var i =0; i < resolution; i++){
    arr.push(i);
  }

  return arr;
};

I'm looking for a similar interface as below but without the above code.

var result = genArray(10).map( i  => {
  return i + 1;
});

console.log(result);
Emanegux
  • 1,000
  • 2
  • 17
  • 37

0 Answers0