Skip to content

Instantly share code, notes, and snippets.

@lacymorrow
Created September 24, 2018 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacymorrow/7693813325bb373ce5054f9f29be53f1 to your computer and use it in GitHub Desktop.
Save lacymorrow/7693813325bb373ce5054f9f29be53f1 to your computer and use it in GitHub Desktop.
Simple function to sum an array
const numbers = [10, 20, 30, 40] // sums to 100
// function for adding two numbers. Easy!
const add = (a, b) =>
a + b
// use reduce to sum our array
const sum = numbers.reduce(add)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment