Find sum of factorials in an array | Function to return the factorial of n ; Function to return the sum of factorials of the array elements ; To store the required sum ; Add factorial of all the elements ; Driver code
function factorial ( n ) { let f = 1 ; for ( let i = 1 ; i <= n ; i ++ ) { f *= i ; } return f ; } function sumFactorial ( arr , n ) { let s = 0 ; for ( let i = 0 ; i < n ; i ++ ) { s += factorial ( arr [ i ] ) ; } return s ; } let arr = [ 7 , 3 , 5 , 4 , 8 ] ; let n = arr . length ; document . write ( sumFactorial ( arr , n ) ) ;