Skip to content

Instantly share code, notes, and snippets.

@pfftdammitchris
Created January 13, 2020 23:03
Show Gist options
  • Save pfftdammitchris/5b3349352c8aaf76b12659f6a3b5f857 to your computer and use it in GitHub Desktop.
Save pfftdammitchris/5b3349352c8aaf76b12659f6a3b5f857 to your computer and use it in GitHub Desktop.
const people = {
bob: {
age: 15,
gender: 'male',
},
jessica: {
age: 24,
gender: 'female',
},
lucy: {
age: 11,
gender: 'female',
},
sally: {
age: 14,
gender: 'female',
},
}
const { males, females } = Object.keys(people).reduce(
(acc, name) => {
const person = people[name]
if (person.gender === 'male') {
acc.males.push(name)
} else {
acc.females.push(name)
}
return acc
},
{ males: [], females: [] },
)
console.log(males) // ["bob"]
console.log(females) // ["jessica", "lucy", "sally"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment