Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
239 B
3
Indexable
Never
function sum(arr, n) {
  if( n<=0) {
    return n ;
  } else {
    return sum(arr, n-1) + arr[n-1]
  }



sum([3,4,5], 3)
    sum([3,4,5], 2) + 5
        sum([3,4,5], 1) + 4 + 5
            sum([3,4,5], 0) + 4 + 5
                1 + 4 + 5