Skip to content

Instantly share code, notes, and snippets.

@ferfabricio
Created March 12, 2019 02:14
Show Gist options
  • Save ferfabricio/6dded3e5d8d3c1ae0b5246350fc1d388 to your computer and use it in GitHub Desktop.
Save ferfabricio/6dded3e5d8d3c1ae0b5246350fc1d388 to your computer and use it in GitHub Desktop.
Spread operator
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