How about splitting things up?
timesTwo = e => e * 2; add = (a, b) => a + b;
const result = arr .map(timesTwo) .map(add) // add index
putting maps on separate lines helps people see it broken in to steps
adding in a comment on the "add" helps because most maps don't usually use index.
you could do .map(addIndex) but I don't like this as the original function can add any two things, not just index
.map(addIndex)
or .map((a, i) => add(a, i)) but that creates another function
.map((a, i) => add(a, i))
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How about splitting things up?
timesTwo = e => e * 2;
add = (a, b) => a + b;
const result = arr
.map(timesTwo)
.map(add) // add index
putting maps on separate lines helps people see it broken in to steps
adding in a comment on the "add" helps because most maps don't usually use index.
you could do
.map(addIndex)
but I don't like this as the original function can add any two things, not just indexor
.map((a, i) => add(a, i))
but that creates another function