Skip to content

Instantly share code, notes, and snippets.

@elliotaplant
Created October 10, 2017 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotaplant/329045305293b9e94560fbda2beb9110 to your computer and use it in GitHub Desktop.
Save elliotaplant/329045305293b9e94560fbda2beb9110 to your computer and use it in GitHub Desktop.
Identity Function
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