code: function alreadySorted(sortDirection, data, comparator) {
    const numRows = data.length;
    if (sortDirection === SortDirection.Ascending) {
      for (let i = 1; i < numRows; i++) {
        if (comparator(data[i - 1], data[i]) > 0) {
          return false;
        }
      }
    // check descending
    } else {
      for (let i = 1; i < numRows; i++) {
        if (comparator(data[i - 1], data[i]) < 0) {
          return false;
        }
      }
    }
  
    return true;
  }
docs: Helper function to test if an array is already sorted
  
  @param {Boolean} sortDirection The direction to check if it is sorted in
  @param {Array} data The data to check
  @param {Function} comparator The comparator to use
  @return {Boolean} True if already sorted, false otherwise