Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Last active January 3, 2020 22:58
Show Gist options
  • Save jbmilgrom/e1c9597822644194e8a54db14fc44686 to your computer and use it in GitHub Desktop.
Save jbmilgrom/e1c9597822644194e8a54db14fc44686 to your computer and use it in GitHub Desktop.
Example of function composition with higher-order function 'reduce'
const square = x => x * x;
const sum = (x, y) => x + y;
const sumOfSquares = (...nums) => nums.reduce((total, num) => sum(total, square(num)), 0);
sumOfSquares(1, 2, 3); // 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment