Introduction
In this lab, we will be working with the isSorted
function in JavaScript to determine whether a numeric array is sorted in ascending or descending order. We will use the Math.sign()
method to convert the final direction value to -1
for descending order and 1
for ascending order. We will also handle cases where the array is empty, has only one element, or the direction changes for any pair of adjacent array elements.