matician - v2.0.0
    Preparing search index...

    Function modeBy

    • Calculates the mode (most frequent numeric value) of a specified property in an array of objects.

      Type Parameters

      • T extends Record<string, any>

        The type of objects in the array.

      Parameters

      • items: T[]

        The array of objects.

      • key: keyof T

        The key whose numeric values will be used.

      Returns number

      The mode value, or NaN if no valid numbers are found.

      const data = [{ a: 1 }, { a: 2 }, { a: 2 }, { a: 3 }];
      modeBy(data, 'a'); // Returns 2