Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/iter/lib/reducers.ts>average

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function average
import { average } from "https://deno.land/x/iter@v3.2.3/lib/reducers.ts";
Finds the average of all items in it.

warning: When ran on an endless iterable, this never returns.

Examples

Example 1

import * as iter from "https://deno.land/x/iter";

const myRange = iter.create.range(1, 100);
console.log(iter.average(myRange)); // -> 50.5

Parameters

it: Iterable<number>
  • The iterable to calculate the average of.

Returns

number

The average of all items in it.