Skip to content

Instantly share code, notes, and snippets.

@aleduca
Created January 4, 2022 14:10
Show Gist options
  • Save aleduca/da3b0cd1844a3c46acb8aca819094912 to your computer and use it in GitHub Desktop.
Save aleduca/da3b0cd1844a3c46acb8aca819094912 to your computer and use it in GitHub Desktop.
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