Largest sub | function to return the length of the largest sub - array of an array every element of whose is a perfect square ; if both a and b are equal then arr [ i ] is a perfect square ; Driver code
function contiguousPerfectSquare ( arr , n ) { var a ; var b ; var current_length = 0 ; var max_length = 0 ; for ( var i = 0 ; i < n ; i ++ ) { b = ( Math . sqrt ( arr [ i ] ) ) ; a = parseInt ( b ) ; if ( a == b ) current_length ++ ; else current_length = 0 ; max_length = Math . max ( max_length , current_length ) ; } return max_length ; } var arr = [ 9 , 75 , 4 , 64 , 121 , 25 ] ; var n = arr . length ; document . write ( contiguousPerfectSquare ( arr , n ) ) ;