Largest number that is not a perfect square | JavaScript program to find the largest non perfect square number among n numbers ; takes the sqrt of the number ; checks if it is a perfect square number ; function to find the largest non perfect square number ; stores the maximum of all non perfect square numbers ; traverse for all elements in the array ; store the maximum if not a perfect square ; Driver Code ; function call
function check ( n ) { let d = Math . sqrt ( n ) ; if ( d * d == n ) return true ; return false ; } function largestNonPerfectSquareNumber ( a , n ) { let maxi = - 1 ; for ( let i = 0 ; i < n ; i ++ ) { if ( ! check ( a [ i ] ) ) maxi = Math . max ( a [ i ] , maxi ) ; } return maxi ; } let a = [ 16 , 20 , 25 , 2 , 3 , 10 ] ; let n = a . length ; document . write ( largestNonPerfectSquareNumber ( a , n ) ) ;