FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Interview-Questions/recursion/011.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
/
011.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
52 lines (39 loc) · 838 Bytes
Breadcrumbs
JavaScript-Interview-Questions
/
recursion
/
011.js
Copy path
File metadata and controls
52 lines (39 loc) · 838 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
44
45
46
47
48
49
50
/*
* <!--
* This program is distributed under
* the terms of the MIT license.
* Please see the LICENSE file for details.
* -->
*/
/*
* Write an iterative method to generate nth Fibonacci number.
* F(n) = F(n-1) + F(n-1); F(0) == 0, F(1) == 1;
*/
/*____________________________________________________________________________*/
function
fibonacci
(
n
)
{
if
(
n
===
0
)
{
return
0
;
}
if
(
n
===
1
)
{
return
1
;
}
if
(
n
<
1
)
{
return
-
1
;
}
var
i
=
0
;
var
c
=
0
;
var
a
=
1
;
var
b
=
1
;
for
(
i
=
3
;
i
<=
n
;
i
++
)
{
c
=
a
+
b
;
a
=
b
;
b
=
c
;
}
return
b
;
}
/*____________________________________________________________________________*/
console
.
log
(
fibonacci
(
99
)
)
;
/*
Output: ($ /usr/bin/node 011.js)
218922995834555200000
*/
Back
|
FazBrowse Home
|
New Git URL