-
Notifications
You must be signed in to change notification settings - Fork 0
functionalProgramming_research
Simon Planje edited this page Nov 12, 2020
·
1 revision
const animals = [
{name: 'Floppy', species: 'rabbit'},
{name: 'Caro', species: 'dog'},
{name: 'Hamilton', species: 'dog'},
{name: 'Harold', species: 'fish'},
{name: 'Ursula', species: 'cat'},
{name: 'Jimmy', species: 'fish'},
]
//How a normal forloop would look like to filter
let dogs = []
for (var i = 0; i < animals.length; i++){
if(animals[i].species === 'dog')
dogs.push(animals[i])
}
//How to rewrite this forloop with a filter function
let dogs = animals.filter(function(animal){
return.species === 'dog'
})