import { LexorankSortable } from "@/utils/lexorank/types";

export function compareByLexorank<T extends LexorankSortable>(
    a: T,
    b: T
): -1 | 1 | 0 {
    return compareByLexorankWithKey<T>(a, b, "lexorank");
}

export function compareByLexorankWithKey<T>(
    a: T,
    b: T,
    key: keyof T
): -1 | 1 | 0 {
    if (a[key] < b[key]) {
        return -1;
    }
    if (a[key] > b[key]) {
        return 1;
    }
    return 0;
}
