Skip to content

Instantly share code, notes, and snippets.

@alexismellamo
Created December 3, 2018 03:38
Show Gist options
  • Save alexismellamo/0787f78e607b28d0c9f26b49658fb1ea to your computer and use it in GitHub Desktop.
Save alexismellamo/0787f78e607b28d0c9f26b49658fb1ea to your computer and use it in GitHub Desktop.
const animals = [
{name: 'Fluffy', species: 'rabbit'},
{name: 'Caro', species: 'dog'},
{name: 'Hamilton', species: 'dog'},
{name: 'Harold', species: 'fish'},
{name: 'Ursula', species: 'cat'},
{name: 'Jimmy', species: 'cat'},
{name: 'Fluffy', species: 'dog'},
]
const filterBySpecie = (specie) => {
return (animal) => {
return animal.species === specie
}
}
const isDog = filterBySpecie('dog')
const isCat = filterBySpecie('cat')
const isRabbit = filterBySpecie('rabbit')
const dogs = animals.filter(isDog)
const rabbits = animals.filter(isCat)
const cats = animals.filter(isRabbit)
dogs
rabbits
cats
// let dogs = []
// for(let i=0; animals.length > i; i++) {
// if(animals[i].species === 'dog') {
// dogs.push(animals[i])
// }
// }
// dogs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment