Skip to content

Instantly share code, notes, and snippets.

@IrhaAli
Created December 4, 2022 00:08
Show Gist options
  • Save IrhaAli/8a60b42099043a98a2a94888d7858a1f to your computer and use it in GitHub Desktop.
Save IrhaAli/8a60b42099043a98a2a94888d7858a1f to your computer and use it in GitHub Desktop.
Sums the items of an array
function sumItems(array) {
if (array.length === 0) {
return 0;
}else if (Array.isArray(array[0])) {
return sumItems(array[0]) + sumItems(array.slice(1));
} else {
return array[0] + sumItems(array.slice(1));
}
}
module.exports = sumItems;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment