forked from jfarmer/exercises-js-fundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fibonacci.js
35 lines (32 loc) · 951 Bytes
/
fibonacci.js
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
/**
* Given a non-negative integer n, returns the n-th Fibonacci numbers.
*
* The Fibonacci numbers are defined thus:
*
* fib(n): 0 1 1 2 3 5 8 13 21 34 55 ...
* n: 0 1 2 3 4 5 6 7 8 9 10 ...
*
* That is, starting with 0 and 1, the next Fibonacci number is the sum
* of the previous two. The "0-th" Fibonacci number is 0 and the first
* Fibonacci number is 1.
*
* See https://en.wikipedia.org/wiki/Fibonacci_number
*
* @example
* fibonacci(0); // => 0
* fibonacci(1); // => 1
* fibonacci(10); // => 55
* fibonacci(12); // => 144
*
* @param {number} n - A non-negative integer
* @returns {number} The fibonacci of num
*/
function fibonacci(n) {
// This is your job. :)
}
if (require.main === module) {
console.log('Running sanity checks for fibonacci:');
// Add your own sanity checks here.
// How else will you be sure your code does what you think it does?
}
module.exports = fibonacci;