Created
January 4, 2022 14:10
-
-
Save aleduca/da3b0cd1844a3c46acb8aca819094912 to your computer and use it in GitHub Desktop.
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
var users = [ | |
{ | |
name: "Alexandre", | |
status: "ativo", | |
}, | |
{ | |
name: "Joao", | |
status: "ativo", | |
}, | |
{ | |
name: "Pedro", | |
status: "inativo", | |
}, | |
]; | |
let usersStatus = users.reduce( | |
(accumulator, user) => { | |
if (user.status === "ativo") { | |
accumulator["ativos"].push(user); | |
} else { | |
accumulator["inativos"].push(user); | |
} | |
return accumulator; | |
}, | |
{ ativos: [], inativos: [] } | |
); | |
console.log(usersStatus); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment