mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00
17 lines
388 B
JavaScript
17 lines
388 B
JavaScript
/**
|
|
* @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)
|
|
*/
|
|
|
|
const fibonacci = (n) => {
|
|
if (n < 2) {
|
|
return n
|
|
}
|
|
return fibonacci(n - 2) + fibonacci(n - 1)
|
|
}
|
|
|
|
export { fibonacci }
|