Skip to content

Instantly share code, notes, and snippets.

@lacymorrow lacymorrow/js-sum.js
Created Sep 24, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.