Skip to content

Check if a number is a Fibonacci in JavaScript

Advertisements
const isFibonacci = (num, count = 1, last = 0) => {
   if(count < num){
      return isFibonacci(num, count+last, count);
   };
   if(count === num){
      return true;
   }
   return false;
};
console.log(isFibonacci(1)); //true
console.log(isFibonacci(2)); //true
console.log(isFibonacci(89)); //true
console.log(isFibonacci(7)); //false
See also  Clone Graph - Leetcode Challenge - Python Solution
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.