Skip to content

Instantly share code, notes, and snippets.

@ravivit9
Created July 11, 2018 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravivit9/3c1874ce56fb78cf377e91028b650bee to your computer and use it in GitHub Desktop.
Save ravivit9/3c1874ce56fb78cf377e91028b650bee to your computer and use it in GitHub Desktop.
The array of objects will be filtered based on a object.property value.
people = [
{name: 'Mary', gender: 'girl'},
{name: 'Paul', gender: 'boy'},
{name: 'John', gender: 'boy'},
{name: 'Lisa', gender: 'girl'},
{name: 'Bill', gender: 'boy'},
{name: 'Maklatura', gender: 'girl'}
]
var numBoys = people.reduce(function (n, person) {
return n + (person.gender == 'boy');
}, 0);
console.log(numBoys);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment