• Selects a weighted random element from an array.

    Type Parameters

    • T extends { weight?: number; [k: string]: any }

      The type of the array.

    Parameters

    • items: T[]

      The array of items to select from.

    • OptionalweightProp: "weight"

      The property to use as the weight.

    Returns T

    The selected item.

  • Selects a weighted random element from an array.

    Type Parameters

    • T extends { [k in string | number | symbol]?: number } & { [k: string]: any }

      The type of the array.

    • K extends string | number | symbol

    Parameters

    • items: T[]

      The array of items to select from.

    • weightProp: K

      The property to use as the weight.

    Returns T

    The selected item.