Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Last active December 8, 2015 19:13
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 ivanoats/ecfb7bae31acebec703b to your computer and use it in GitHub Desktop.
Save ivanoats/ecfb7bae31acebec703b to your computer and use it in GitHub Desktop.
var square = function(x) {
return x * x;
}
var sum = function(accumulator, x) {
return accumulator + x;
}
function sumOfSquares2(nums) {
return nums
.map(square)
.reduce(sum);
}
console.log(sumOfSquares2([1, 2, 3, 4, 5]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment