matician - v2.0.0
    Preparing search index...

    Function medianBy

    • Calculates the median of a specified numeric 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 median value, or NaN if no valid numbers are found.

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