JavaScript has no TreeSet. Implement a class OrderedSet of distinct numbers that supports ordered queries, using a sorted array and binary search.
add(x): insert x; return true if it was new, false if already presentremove(x): delete x; return true if it was present, false otherwisehas(x), size()floor(x): the largest value ≤ x, or null; ceiling(x): the smallest value ≥ x, or nullrank(x): how many stored values are smaller than x (works whether or not x is stored)kth(k): the k-th smallest, counting from 1, or null if k is out of range- Finding a position must be O(log n); the shift on insert and delete may cost O(n). Do not sort on every query