Split the array into odd number of segments of odd lengths | Function to check ; Check the result by processing the first & last element and size ; Driver code
function checkArray ( arr , n ) { return ( ( arr [ 0 ] % 2 ) > 0 && ( arr [ n - 1 ] % 2 ) > 0 && ( n % 2 ) > 0 ) ? 1 : 0 ; } var arr = [ 1 , 2 , 3 , 4 , 5 ] ; var n = arr . length ; document . write ( checkArray ( arr , n ) ) ;