Function isSorted

  • Category

    Check whether an array is sorted according to a given compare function.

    Time complexity: O(n)

    Space complexity: O(1)

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      Array to check

    • compareFn: CompareFn<T>

      Function to compare elements

    Returns boolean

    Whether the array is sorted according to the given compare function

    Sort

    import { Sort } from '@jonahsnider/util';

    const array = [1, 2, 3, 4, 5];

    isSorted(array, (a, b) => a - b);