lukehoban/es6features

I expected nums to be [1,2,3]

lucidtech opened this issue · 1 comments

var nums = evens.map((v, i) => v + i);
nums returns [0,3,6..]
why not v-i that returns [1,2,3]

... confused

Not sure what issue you are pointing out here.

The map function takes a callback and invokes it with the value (v) and index (i) of each element.

So this example:

let evens = [0,2,4]
let nums = evens.map((v,i) => v + i)
console.log(nums)

Will print [0,3,6].

See example on babeljs.