-
-
Save IrhaAli/8a60b42099043a98a2a94888d7858a1f to your computer and use it in GitHub Desktop.
Sums the items of an array
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
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