Created
October 10, 2014 15:29
-
-
Save kinsteronline/d3787102c94bc5dbbece to your computer and use it in GitHub Desktop.
Sum it up more modern style?
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
export function sum(...a) { | |
function loop(arr, total = 0) { | |
if (arr.length === 0) return total; | |
else return loop(arr.slice(1), total + arr[0]); | |
} | |
return loop(a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment