/** * Enables a comparison of arbitrary values with support for undefined/null. * Requires the `<` and `>` operators to return something reasonable for the provided values. */ export function compare(x?: T, y?: T) { if (x == undefined && y == undefined) { return 0; } else if (x == undefined) { return -1; } else if (y == undefined) { return 1; } else if (x < y) { return -1; } else if (x > y) { return 1; } else { return 0; } }