Skip to content

Instantly share code, notes, and snippets.

@bjdixon
Created September 8, 2015 20:47
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 bjdixon/835da5e4912514386b47 to your computer and use it in GitHub Desktop.
Save bjdixon/835da5e4912514386b47 to your computer and use it in GitHub Desktop.
take an array and return an array with falsy values removed
function compact(a) {
return a.reduce(function(memo, x) {
return x ? memo.concat(x) : memo;
}, []);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment