Find the next Factorial greater than N | Array that stores the factorial till 20 ; Function to pre - compute the factorial till 20 ; Precomputing factorials ; Function to return the next factorial number greater than N ; Traverse the factorial array ; Find the next just greater factorial than N ; Function to precalculate the factorial till 20 ; Function call
fact = Array ( 21 ) . fill ( 0 ) ; function preCompute ( ) { fact [ 0 ] = 1 ; for ( var i = 1 ; i < 18 ; i ++ ) fact [ i ] = ( fact [ i - 1 ] * i ) ; } function nextFactorial ( N ) { for ( var i = 0 ; i < 21 ; i ++ ) { if ( N < fact [ i ] ) { document . write ( fact [ i ] ) ; break ; } } } preCompute ( ) ; var N = 120 ; nextFactorial ( N ) ;