Check if a number is Full Fibonacci or not | A utility function that returns true if x is perfect square ; Returns true if N is a fibonacci number and false otherwise ; N is fibonacci if one of 5 * N ^ 2 + 4 or 5 * N ^ 2 - 4 or both is a perferct square ; Function to check digits ; Check if all digits are fibonacci or not ; Extract digit ; Check if the current digit is not fibonacci ; Function to check and return if N is a full fibonacci number or not ; Driver code
function isPerfectSquare ( x ) { var s = parseInt ( Math . sqrt ( x ) ) ; return ( s * s == x ) ; } function isFibonacci ( n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } function checkDigits ( n ) { while ( n != 0 ) { var dig = n % 10 ; if ( dig == 4 && dig == 6 && dig == 7 && dig == 9 ) return false ; n /= 10 ; } return true ; } function isFullfibonacci ( n ) { return ( checkDigits ( n ) && isFibonacci ( n ) ) ; } var n = 13 ; if ( isFullfibonacci ( n ) ) document . write ( " " ) ; else document . write ( " " ) ;