isSorted
Checks if a numeric array is sorted.
- Calculate the ordering
directionfor the first pair of adjacent array elements. - Return
0if the given array is empty, only has one element or thedirectionchanges for any pair of adjacent array elements. - Use
Math.sign()to covert the final value ofdirectionto-1(descending order) or1(ascending order).