Last active
June 23, 2017 06:43
-
-
Save chriswrightdesign/d5e229c50871f314dac736bfa5f0d8f6 to your computer and use it in GitHub Desktop.
Passing functions to map
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 myAnimals = ['dog', undefined, 'cat', 'bird', undefined, 0, false]; | |
myAnimals.filter(Boolean); // Result: ['dog', 'cat', 'bird']; | |
/* | |
it will call Boolean('dog'), then Boolean(undefined), | |
then Boolean('cat') etc etc, the array.filter() callback must return true to keep | |
an element in the array, if its false it excludes it | |
*/ | |
const myValues = [1.34, 3.5, 3.6, 4.1]; | |
// now using Math.round() on .map() | |
myValues.map(Math.round) // [1, 4, 4, 4]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment