Check whether a number is a Fibonacci number or not JavaScript

We are required to write a JavaScript function that takes in a number and returns a boolean based on the fact whether or not it comes in the fibonacci series.

For example −

If the function call is like this −

fibonacci(12);
fibonacci(89);
fibonacci(55);
fibonacci(534);

Then the output should be −

False
true
true
false

Now, let’s write a recursive solution to this problem −

Example

const fibonacci = (query, count = 1, last = 0) => {
   if(count 

Output

The output in the console will be −

false
true
true
false
Updated on: 2020-08-28T14:01:00+05:30

499 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements