Created
March 12, 2019 02:14
-
-
Save ferfabricio/6dded3e5d8d3c1ae0b5246350fc1d388 to your computer and use it in GitHub Desktop.
Spread operator
This file contains 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
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
const resultado = items.reduce( | |
(acc, curr) => { | |
if (curr % 2 === 0) { | |
return { | |
...acc, | |
pares: [ | |
...acc.pares, | |
curr | |
] | |
} | |
} | |
return { | |
...acc, | |
impares: [ | |
...acc.impares, | |
curr | |
] | |
} | |
}, | |
{ pares: [], impares: [] } | |
) | |
console.log(resultado) | |
// Resultado | |
// { pares: [ 2, 4, 6, 8, 10 ], impares: [ 1, 3, 5, 7, 9 ] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment