Created
November 28, 2016 01:21
-
-
Save violet-athena/0124b5affb51216402b69348d24591ac to your computer and use it in GitHub Desktop.
Javascript Sum of Array in one line
This file contains hidden or 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
// manual implementation | |
const sum = ([first, ...rest]) => rest.length ? first + sum(rest) : first; | |
// using reduce | |
const sum = arr => arr.reduce((acc, el) => acc + el, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment