File tree Expand file tree Collapse file tree
05 - Objects-And-Functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // 1
2+ function countFuction ( num ) {
3+ console . log ( num ) ;
4+ if ( num <= 0 ) {
5+ return ;
6+ }
7+
8+ countFuction ( num - 1 ) ;
9+ }
10+
11+ countFuction ( 8 ) ;
12+
13+ // 2
14+ function anotherAountFuction ( num ) {
15+ console . log ( num ) ;
16+ if ( num > 0 ) {
17+ anotherAountFuction ( num - 1 ) ;
18+ }
19+ }
20+
21+ anotherAountFuction ( 8 ) ;
22+
23+ // sum of digits
24+ function sumOfDigits ( num ) {
25+ if ( num == 0 ) {
26+ return 0 ;
27+ }
28+ return ( num % 10 ) + sumOfDigits ( Math . floor ( num / 10 ) ) ;
29+ }
30+
31+ let sum = sumOfDigits ( 324 ) ;
32+ console . log ( `res = ${ sum } ` ) ;
33+
34+ // factorial
35+ var factorial = function ( number ) {
36+ // break condition
37+ if ( number <= 0 ) {
38+ return 1 ;
39+ }
40+
41+ // block to execute
42+ return number * factorial ( number - 1 ) ;
43+ } ;
44+
45+ console . log ( `Factorial = ${ factorial ( 9 ) } ` ) ;
You can’t perform that action at this time.
0 commit comments