Created
September 24, 2018 10:15
-
-
Save lacymorrow/7693813325bb373ce5054f9f29be53f1 to your computer and use it in GitHub Desktop.
Simple function to sum an array
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 = [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