Javascript: Fibonacci

JavaScript fundamentals
Last update: 14 Sep 10:09
2
Students
50%
Completion rate

src/solution.js

Implement the fib() function and export it as default. The function calculates positive Fibonacci numbers. It takes an ordinal number (of a Fibonacci number) on input.

Formula:

f(0) = 0
f(1) = 1
f(n) = f(n-1) + f(n-2)
fib(3);  // 2
fib(5);  // 5
fib(10); // 55

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests