Category
A function that maps elements from type T
to a Comparable
A compare function that returns a positive value if first argument is less than second argument, zero if they're equal and a negative value otherwise
Sort
const array = [{ value: 2 }, { value: 3 }, { value: 1 }, { value: 3 }];
array.sort(Sort.descending(x => x.value));
Category
Sort an array in descending order (greatest to least).
Time complexity: O(1)
Space complexity: O(1)
Element to compare
Element to compare
A positive value if first argument is less than second argument, zero if they're equal and a negative value otherwise
Sort
const array = [5, 3, 2, 4, 1];
array.sort(Sort.descending);
Sort an array in descending order (greatest to least), while applying a function to each element to map the value before comparing.
Time complexity: O(1)
Space complexity: O(1)