Category
Check whether an array is sorted according to a given compare function.
Time complexity: O(n)
Space complexity: O(1)
Array to check
Function to compare elements
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); Copy
import { Sort } from '@jonahsnider/util';const array = [1, 2, 3, 4, 5];isSorted(array, (a, b) => a - b);
Check whether an array is sorted according to a given compare function.
Time complexity: O(n)
Space complexity: O(1)