text: Largest and smallest Fibonacci numbers in an Array | Function to create hash table to check Fibonacci numbers ; Insert initial two numbers in the hash table ; Sum of previous two numbers ; Update the variable each time ; Function to find minimum and maximum fibonacci number in given array ; Find maximum value in the array ; Creating a set containing all Fibonacci numbers up to maximum value in the array ; For storing the Minimum and Maximum Fibonacci number ; Check if current element is a fibonacci number ; Update the maximum and minimum accordingly ; Driver code
code: function createHash ( hash , maxElement ) { let prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { let temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } function fibonacci ( arr , n ) { let max_val = Math . max ( ... arr ) ; let hash = new Set ( ) ; createHash ( hash , max_val ) ; let minimum = Number . MAX_VALUE ; let maximum = Number . MIN_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( hash . has ( arr [ i ] ) ) { minimum = Math . min ( minimum , arr [ i ] ) ; maximum = Math . max ( maximum , arr [ i ] ) ; } } document . write ( minimum + " " + maximum + " " ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ; let n = arr . length ; fibonacci ( arr , n ) ;