Skip to content

v3.22.10

Latest

Choose a tag to compare

@graphieros graphieros released this 12 Jul 08:40

Utility functions

Add the following utilities:

average

Calculates the average of all finite numbers in an array.
Invalid values are ignored, and the original array is not mutated.
Returns null when the input is not an array or contains no finite numbers.

import { average } from "vue-data-ui/utils";

const average = average([0, 10]); // 5

const averageWithInvalidValues = average([0, undefined, 5, NaN, Infinity, -Infinity, 'text', null, 10]); // 5

const invalidAverage = average([]); // null

median

Calculates the median of all finite numbers in an array.
Invalid values are ignored, and the original array is not mutated.
Returns null when the input is not an array or contains no finite numbers.

import { median } from "vue-data-ui/utils";

const median = median([1, 3, 5, 7]); // 4

const medianWithInvalidValues = median([1, undefined, 3, NaN, null, Infinity, -Infinity, 'text', 5]); // 3

const invalidMedian = median([]); // null

Docs are up to date