Created
June 4, 2019 14:36
-
-
Save evanwinter/3bc944e8a690c6de60c4f8d99ad24431 to your computer and use it in GitHub Desktop.
Simple examples of Array::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 numbers = [1, 3, 5, 1, 23, 5] | |
// Adds two args | |
const add = (one, two) => one + two | |
// Compute sum of the collection | |
const sum = numbers.reduce((sum, number) => add(sum, number)) | |
// Multiplies two args | |
const multiply = (one, two) => one * two | |
// Compute product of the collection | |
const product = numbers.reduce((product, number) => multiply(product, number)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment