Skip to content

Instantly share code, notes, and snippets.

@OneCent01
Created June 15, 2017 21:10
Show Gist options
  • Save OneCent01/982f7d7a9638f35c504b4cb80f9947e4 to your computer and use it in GitHub Desktop.
Save OneCent01/982f7d7a9638f35c504b4cb80f9947e4 to your computer and use it in GitHub Desktop.
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