Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
41 lines (30 loc) · 707 Bytes

File metadata and controls

41 lines (30 loc) · 707 Bytes
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
/*
* <!--
* This program is distributed under
* the terms of the MIT license.
* Please see the LICENSE file for details.
* -->
*/
/*
* Write a recursive 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;
}
return fibonacci(n-1) + fibonacci(n-2);
}
/*____________________________________________________________________________*/
console.log( fibonacci(42) );
/*
Output: ($ /usr/bin/node 010.js)
267914296
*/
Morty Proxy This is a proxified and sanitized view of the page, visit original site.