Javascript soln using mathematical approach factorial array is stored dynamically
let fact = [ 1 ] ; function preComputeFact ( n ) { for ( let i = 1 ; i < n + 1 ; i ++ ) { fact . push ( ( fact [ i - 1 ] * i ) ) ; } }