Skip to content

fibonacci ​

Calculates the n-th number in the Fibonacci sequence.

Syntax ​

typescript
fibonacci(num: number): number

Parameters ​

NameTypeDescription
nnumberNon-negative integer index.

Return ​

TypeDescription
numberThe nth Fibonacci number.

Example ​

typescript
fibonacci(0); // 0
fibonacci(1); // 1
fibonacci(6); // 8

Notes ​

  • Throws TypeError if the argument is not a non-negative integer.
  • Recursive implementation; for large values, consider an iterative approach.

References ​

Released under the MIT License.