const desc = (a, b) => b - a;
sorter([3, 1, 2], desc); // [3, 2, 1]Pass a descending comparator to change sorting behavior without changing the sorter.
The same Sorter class can use a different strategy to sort in descending order.
Challenge: Implement a Sorter class that works with both ascending and descending strategies.
Example:
const ascending = (a, b) => a - b
const descending = (a, b) => b - a
const asc = new Sorter(ascending)
const desc = new Sorter(descending)
asc.sort([3, 1, 2]) // [1, 2, 3]
desc.sort([3, 1, 2]) // [3, 2, 1]