Solving f ( n ) = ( 1 ) + ( 2 * 3 ) + ( 4 * 5 * 6 ) . . . n using Recursion | * * Recursive method for finding * sum of series * * @ param calculated number of terms * till which sum of terms has been * calculated @ param current number of * terms for which sum has to be calculated . * @ param N Number of terms in the function * to be calculated @ return sum ; checking termination condition ; product of terms till current ; recursive call for adding terms next in the series ; input number of terms in the series ; invoking the method to calculate the sum
function seriesSum ( calculated , current , N ) { let i , cur = 1 ; if ( current == N + 1 ) return 0 ; for ( i = calculated ; i < calculated + current ; i ++ ) cur *= i ; return cur + seriesSum ( i , current + 1 , N ) ; } let N = 5 ; document . write ( seriesSum ( 1 , 1 , N ) ) ;