Last active
January 3, 2020 22:58
-
-
Save jbmilgrom/e1c9597822644194e8a54db14fc44686 to your computer and use it in GitHub Desktop.
Example of function composition with higher-order function 'reduce'
This file contains 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
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