Skip to content

Instantly share code, notes, and snippets.

@LeighCiechanowski
Created October 12, 2018 08:29
Show Gist options
  • Save LeighCiechanowski/dc49a00582c5226d77ece4b261bcca2e to your computer and use it in GitHub Desktop.
Save LeighCiechanowski/dc49a00582c5226d77ece4b261bcca2e to your computer and use it in GitHub Desktop.
Filter Map Reduce
const data = [
{
name: 'Butters',
age: 3,
type: 'dog'
},
{
name: 'Lizzy',
age: 6,
type: 'dog'
},
{
name: 'Red',
age: 1,
type: 'cat'
},
{
name: 'Joey',
age: 3,
type: 'dog'
},
];
const dog = (animal) => animal.type === 'dog';
const dogYears = (animal) => animal.age * 7;
const sum = (acc, age) => acc + age;
const sumInDogYears = data.filter(dog)
.map(dogYears).reduce(sum);
console.log(sumInDogYears);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment