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