Created
June 15, 2017 21:10
-
-
Save xfateless/982f7d7a9638f35c504b4cb80f9947e4 to your computer and use it in GitHub Desktop.
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
var arraySum = function(array) { | |
var total = 0; | |
if(array.length === 0) { | |
return 0; | |
} | |
var popped = array.pop(); | |
if(Array.isArray(popped)) { | |
total += arraySum(popped); | |
return total += arraySum(array); | |
} | |
return total += popped + arraySum(array); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment