Created
December 3, 2018 03:38
-
-
Save alexismellamo/0787f78e607b28d0c9f26b49658fb1ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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