mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
merge: Add test cases (#854)
This commit is contained in:
@ -1,15 +1,17 @@
|
||||
|
||||
// https://en.wikipedia.org/wiki/Fibonacci_number
|
||||
|
||||
/**
|
||||
* Return the N-th Fibonacci number
|
||||
*
|
||||
* @param {number} N
|
||||
* @returns {number}
|
||||
* @function Fibonacci
|
||||
* @description Function to return the N-th Fibonacci number.
|
||||
* @param {Integer} n - The input integer
|
||||
* @return {Integer} - Return the N-th Fibonacci number
|
||||
* @see [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number)
|
||||
*/
|
||||
export const fibonacci = (N) => {
|
||||
if (N === 0 || N === 1) {
|
||||
return N
|
||||
|
||||
const fibonacci = (n) => {
|
||||
if (n < 2) {
|
||||
return n
|
||||
}
|
||||
return fibonacci(N - 2) + fibonacci(N - 1)
|
||||
return fibonacci(n - 2) + fibonacci(n - 1)
|
||||
}
|
||||
|
||||
export { fibonacci }
|
||||
|
Reference in New Issue
Block a user