Last active
January 3, 2019 08:30
-
-
Save munkacsitomi/a79ea3af0eacaa5ebf2e3ff58a5ba5e7 to your computer and use it in GitHub Desktop.
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
| const kittens = animals.find(x => x.type === 'cat' && x.ageMonths < 12); | |
| const kittens = animals.find(animal => animal.type === 'cat' && animal.ageMonths < 12); | |
| const kittens = animals.filter(animal => animal.type === 'cat').filter(cat => cat.ageMonths < 12); | |
| const kittens = animals.filter(onlyKittens); | |
| const onlyKittens = ({ type, ageMonths }) => type === 'cat' && ageMonths < 12; | |
| // When to use map? | |
| // .map() when you want to transform elements in an array. | |
| // When to use filter? | |
| // .filter() when you want to select a subset of multiple elements from an array. | |
| // When to use find? | |
| // .find() When you want to select a single element from an array. | |
| // When to use reduce? | |
| // .reduce() when you want derive a single value from multiple elements in an array. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment