text: Program to check if an array is sorted or not ( Iterative and Recursive ) | Function that returns true if array is sorted in non - decreasing order . ; Array has one or no element ; Unsorted pair found ; No unsorted pair found ; Driver Code
code: function arraySortedOrNot ( arr , n ) { if ( n == 0 n == 1 ) return true ; for ( let i = 1 ; i < n ; i ++ ) if ( arr [ i - 1 ] > arr [ i ] ) return false ; return true ; } let arr = [ 20 , 23 , 23 , 45 , 78 , 88 ] ; let n = arr . length ; if ( arraySortedOrNot ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;