Created
October 10, 2017 23:33
-
-
Save elliotaplant/329045305293b9e94560fbda2beb9110 to your computer and use it in GitHub Desktop.
Identity Function
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
var myList = [0, 1, 2, true, false, null, undefined, '', [], {}]; | |
function identity(i) { | |
return i; | |
} | |
// Filtering with the identity function will filter out the non-truthy values | |
var truthies = myList.filter(identity); | |
console.log(truthies); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment