Last active
August 15, 2017 06:02
-
-
Save astfarias/33e7068847dc1e08b0b7cff41ad3da2a to your computer and use it in GitHub Desktop.
JS - Functional Programming - Higher-order Functions - filter()
This file contains hidden or 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
| // Example of filter as a higher-order function because uses a callback function | |
| var animals = [ | |
| { name: 'Fluffykins', species: 'rabbit' }, | |
| { name: 'Caro', species: 'dog' }, | |
| { name: 'Hamilton', species: 'dog' }, | |
| { name: 'Harold', species: 'fish' }, | |
| { name: 'Ursula', species: 'cat' }, | |
| ]; | |
| var dogs = animals.filter(function(animal){ | |
| return animal.species === 'dog' | |
| }); | |
| /** | |
| [ { name: 'Caro', species: 'dog' }, | |
| { name: 'Hamilton', species: 'dog' } ] | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment