Skip to content

Instantly share code, notes, and snippets.

@Shobhit1
Forked from OneCent01/recursion addition
Created June 26, 2018 04:38
Show Gist options
  • Save Shobhit1/bb6265111727f11d4cd43545ddf92be2 to your computer and use it in GitHub Desktop.
Save Shobhit1/bb6265111727f11d4cd43545ddf92be2 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