Check if an array is increasing or decreasing | Function to check the type of the array ; If the first two and the last two elements of the array are in increasing order ; If the first two and the last two elements of the array are in decreasing order ; If the first two elements of the array are in increasing order and the last two elements of the array are in decreasing order ; If the first two elements of the array are in decreasing order and the last two elements of the array are in increasing order ; Driver code
function checkType ( arr , n ) { if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] <= arr [ n - 1 ] ) document . write ( " " ) ; else if ( arr [ 0 ] >= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) document . write ( " " ) ; else if ( arr [ 0 ] <= arr [ 1 ] && arr [ n - 2 ] >= arr [ n - 1 ] ) document . write ( " " ) ; else document . write ( " " ) ; } let arr = [ 1 , 2 , 3 , 4 ] ; let n = arr . length ; checkType ( arr , n ) ;