FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Interview-Questions/recursion/001.js at master · devangnpatil/JavaScript-Interview-Questions · GitHub
devangnpatil
/
JavaScript-Interview-Questions
Public
forked from
aishraj/JavaScript-Interview-Questions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Interview-Questions
/
recursion
/
001.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (36 loc) · 837 Bytes
Breadcrumbs
JavaScript-Interview-Questions
/
recursion
/
001.js
Copy path
File metadata and controls
45 lines (36 loc) · 837 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* <!--
* This program is distributed under
* the terms of the MIT license.
* Please see the LICENSE file for details.
* -->
*/
/*
* Write a function that calculates the factorial of a given number recursively.
*/
/*____________________________________________________________________________*/
/**
*
@function
{
public static
} factorial
*
* Recursively calculates the factorial of a given number.
*
*
@param
{
Integer
} n - the number to calculate.
*
*
@return
the factorial of the given number.
*/
function
factorial
(
n
)
{
if
(
n
>
1
)
{
return
n
*
factorial
(
n
-
1
)
;
}
return
1
;
}
/*____________________________________________________________________________*/
console
.
log
(
factorial
(
4
)
)
;
console
.
log
(
factorial
(
5
)
)
;
console
.
log
(
factorial
(
6
)
)
;
/*
Output: ($ /usr/bin/node 001.js)
24
120
720
*/
Back
|
FazBrowse Home
|
New Git URL