Skip to content

Instantly share code, notes, and snippets.

@csndra0504
Last active March 12, 2017 17:51
Show Gist options
  • Save csndra0504/d5ad7ea308546afee51ff0bfef80dae0 to your computer and use it in GitHub Desktop.
Save csndra0504/d5ad7ea308546afee51ff0bfef80dae0 to your computer and use it in GitHub Desktop.
Sum Squares from 1 to n with JavaScript (ES6)
// sum the squares from 1 to N
const square = x => x * x;
const add = (a, b) => a + b;
const sumSquares = n => Array.from(Array(n+1).keys())
.map(square)
.reduce(add);
console.log(sumSquares(5));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment