| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cc34088 commit 027c0d6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,17 @@ | |||
| 1 | 1 | ||
| 2 | - // https://en.wikipedia.org/wiki/Fibonacci_number | ||
| 3 | - | ||
| 4 | 2 | /** | |
| 5 | - * Return the N-th Fibonacci number | ||
| 6 | - * | ||
| 7 | - * @param {number} N | ||
| 8 | - * @returns {number} | ||
| 3 | + * @function Fibonacci | ||
| 4 | + * @description Function to return the N-th Fibonacci number. | ||
| 5 | + * @param {Integer} n - The input integer | ||
| 6 | + * @return {Integer} - Return the N-th Fibonacci number | ||
| 7 | + * @see [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number) | ||
| 9 | 8 | */ | |
| 10 | - export const fibonacci = (N) => { | ||
| 11 | - if (N === 0 || N === 1) { | ||
| 12 | - return N | ||
| 9 | + | ||
| 10 | + const fibonacci = (n) => { | ||
| 11 | + if (n < 2) { | ||
| 12 | + return n | ||
| 13 | 13 | } | |
| 14 | - return fibonacci(N - 2) + fibonacci(N - 1) | ||
| 14 | + return fibonacci(n - 2) + fibonacci(n - 1) | ||
| 15 | 15 | } | |
| 16 | + | ||
| 17 | + export { fibonacci } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + import { fibonacci } from '../FibonacciNumberRecursive' | ||
| 2 | + | ||
| 3 | + describe('FibonacciNumberRecursive', () => { | ||
| 4 | + it('should return 0', () => { | ||
| 5 | + expect(fibonacci(0)).toBe(0) | ||
| 6 | + }) | ||
| 7 | + | ||
| 8 | + it('should return 1', () => { | ||
| 9 | + expect(fibonacci(1)).toBe(1) | ||
| 10 | + }) | ||
| 11 | + | ||
| 12 | + it('should return 5', () => { | ||
| 13 | + expect(fibonacci(5)).toBe(5) | ||
| 14 | + }) | ||
| 15 | + | ||
| 16 | + it('should return 9', () => { | ||
| 17 | + expect(fibonacci(9)).toBe(34) | ||
| 18 | + }) | ||
| 19 | + }) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments