Last active
January 20, 2016 15:13
-
-
Save zwacky/4483216adc239c0f10c1 to your computer and use it in GitHub Desktop.
ES6 spread to the rescue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get all items of all players | |
/* WITHOUT ES6 spread operator */ | |
const items = []; | |
players.forEach((player) => { | |
player.forEach((item) => { | |
items.push(item); | |
}); | |
}); | |
/* WITH ES6 spread operator */ | |
const items = players.reduce((items, player) => […items, …player.items], []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment