File tree Expand file tree Collapse file tree
JavaScript Interview Programs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11
2- // ******************************************************** Factorial **************************************************
2+ // ****************************************************************************** Factorial ***************************** **************************************************
33
44// 1. Find Factorial of a Number:
5- // Find factorial using loop:
5+
6+ // Find factorial using For loop:
67function factorial ( n ) {
78 let fact = 1 ;
89 for ( let i = 1 ; i <= n ; i ++ ) {
9- fact *= i ; // fact = fact * i;
10+ fact *= i ;
11+ // fact = fact * i;
1012 }
1113 return fact ;
1214}
1315console . log ( "Factorial using For Loop:" , factorial ( 5 ) ) ;
16+
1417// Output:
1518// Factorial using For Loop: 120
1619
@@ -22,5 +25,6 @@ function factorial(n) {
2225 return n * factorial ( n - 1 ) ;
2326}
2427console . log ( "Factorial using Recursion:" , factorial ( 5 ) ) ;
28+
2529// Output:
2630// Factorial using Recursion: 120
You can’t perform that action at this time.
0 commit comments