Skip to content

Instantly share code, notes, and snippets.

@evanwinter
Created June 4, 2019 14:36
Show Gist options
  • Save evanwinter/3bc944e8a690c6de60c4f8d99ad24431 to your computer and use it in GitHub Desktop.
Save evanwinter/3bc944e8a690c6de60c4f8d99ad24431 to your computer and use it in GitHub Desktop.
Simple examples of Array::reduce
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