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

export function getMaxByLexorank<T extends LexorankSortable>(
    items: T[]
): T | null {
    return items.reduce(
        (max, item) => (!max || item.lexorank > max.lexorank ? item : max),
        null as T | null
    );
}

export function getMaxLexorankByKey<T>(items: T[], key: keyof T): T | null {
    return items.reduce(
        (max, item) => (!max || item[key] > max[key] ? item : max),
        null as T | null
    );
}
