Skip to content

meanBy() function

각 요소에 f를 적용한 값들의 평균을 반환합니다. 빈 iterable이면 NaN을 반환합니다.

Signature:

typescript
function meanBy<A>(f: (a: A) => number, iterable: Iterable<A>): number;
function meanBy<A>(
  f: (a: A) => number,
  iterable: AsyncIterable<A>,
): Promise<number>;

Example

ts
meanBy(
  (a) => a.score,
  [
    { name: "a", score: 80 },
    { name: "b", score: 100 },
  ],
); // 90

meanBy((a) => a.score, []); // NaN

pipe(
  [{ score: 80 }, { score: 100 }],
  meanBy((a) => a.score),
); // 90

Open Source Code

Released under the Apache-2.0 License.