Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Created November 7, 2013 02:26
Show Gist options
  • Save animatedlew/7347918 to your computer and use it in GitHub Desktop.
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.
_.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