If sum is perfect square
if ( isPerfectSquare ( sum ) ) { found = true ; ans [ 0 ] = j - k + 1 ; ans [ 1 ] = j ; } } for ( var k = ans [ 0 ] ; k <= ans [ 1 ] ; k ++ ) { document . write ( arr [ k ] + " " ) ; } }