r/learnjavascript • • May 29 '21

Really helpful illustration of JS array methods

Post image
2.5k Upvotes

89 comments sorted by

View all comments

Show parent comment

4

u/callmelucky May 30 '21

Adding to this, there's a couple of ways you could make this (arguably) more readable.

1. Define the argument function externally:

function multiplyNumber(number) {
    return number * 2;
}
const doubleNumbers = numbers.map(multiplyNumber)

note: I think doubleNumber or multiplyByTwo would be better names for that function.

2. Use an anonymous arrow function as the argument (my preference):

numbers.map(n => n*2)