Created
February 2, 2012 23:46
-
-
Save divarvel/1726491 to your computer and use it in GitHub Desktop.
flatten & flatMap
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
function flatten(list) { | |
return _.reduce(list, function(acc, item) { | |
return acc.concat(item); | |
}, []); | |
} | |
function flatMap(list, func, context) { | |
return flatten(_.map(list, func, context)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment