Need to create a function that will return the sum of all elements in an array, but if the array contains strings like
["a","b","c"] // output : abc
Currently, I have this code:
function calculateSumRecursion(array) {
//your code
if (array.length === 0 ) {
return 0
}
return array[0] + calculateSumRecursion(array.slice(1))
}
I am able to calculate the sum of numbers using recursion, however, when it's an array of strings like
array = ["a","b","c"]
it returns
// abc0
due to the if statement.. Is there a way to make it so that
if (array.length === 0) return nothing instead of a 0 (that only works for arrays of numbers)?