Created
November 7, 2013 02:26
-
-
Save animatedlew/7347918 to your computer and use it in GitHub Desktop.
Here is an example of reducing sublists to their sums using functional JavaScript.
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
_.chain([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | |
// Grab each sublist and... | |
.map(function(sublist) { | |
// Sum each of its elements up! | |
return _.reduce(sublist, function(total, num) { | |
return total += num; | |
}); | |
}).value(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment