3.1.1 • Published 6 months ago

math-helper-functions v3.1.1

Weekly downloads
405
License
MIT
Repository
github
Last release
6 months ago

math-helper-functions

Installation

Using npm, npm i math-helper-functions.

Using yarn, yarn add math-helper-functions.

Usage

Using import

import { calcSum } from 'math-helper-functions';

const input = [
  { item: 'bookA', count: 3 },
  { item: 'bookB', count: 4 },
];

const totalBooks = calcSum(input, 'count'); // totalBooks is 7

In a CommonJS environment

const { calcDomain } = require('math-helper-functions');

const input = [
  { item: 'bookA', count: 3 },
  { item: 'bookB', count: 10 },
  { item: 'bookC', count: 1 },
];

const domain = calcDomain(input, 'count'); // domain is [1, 10]

Table of contents

Functions

Functions

calcBuckets

calcBuckets(array, strict?, numOfBins?): IBucket[]

Calculate the buckets given a data array and an amount

Parameters

NameTypeDefault valueDescription
arraynumber[]undefinedThe data array
strict?booleanfalseWhether to use real or pretty domain
numOfBins?numberundefinedAmount of desired buckets

Returns

IBucket[]

The buckets

Export

Defined in

modules/distributions.ts:58


calcDiff

calcDiff(array, property?): number

Gets the absolute difference between the max and min value in an array

Parameters

NameTypeDescription
arrayany[]Input array
property?stringProperty to map by

Returns

number

Absolute difference between the max and min of an array

Export

Defined in

modules/domain.ts:48


calcDistribution

calcDistribution(array, strict?, numOfBins?): IDistribution

Calculates the distribution of an arrays values

Parameters

NameTypeDefault valueDescription
arraynumber[]undefinedInput array
strictbooleanfalse
numOfBins?numberundefinedNumber of bins to use

Returns

IDistribution

The distribution

Export

Defined in

modules/distributions.ts:105


calcDistributionAsArray

calcDistributionAsArray(array, binsStrict?, numOfBins?): IDistributionArrayItem[]

Calculates the distribution of an arrays values and outputs an array

Parameters

NameTypeDefault valueDescription
arraynumber[]undefinedArray to calc distribution of
binsStrict?booleanfalseIf false, buckets may be rounded floor, ceil
numOfBins?numberundefinedNumber of bins to use

Returns

IDistributionArrayItem[]

The distribution as an array of objects

Export

Defined in

modules/distributions.ts:196


calcDistributionWithSeries

calcDistributionWithSeries(buckets, dataGrouped, distributionProp): ISerieDistribution

Calculates the distribution of an array of grouped objects

Parameters

NameType
bucketsIBucket[]
dataGroupedRecord<string, unknown[]>
distributionPropstring

Returns

ISerieDistribution

The distribution with labels and data

Export

Defined in

modules/distributions.ts:140


calcDomain

calcDomain(array, property?): number, number | any, any

Gets the min, max value in an array

Parameters

NameTypeDescription
arrayany[]Input array
property?stringProperty to map by

Returns

number, number | any, any

The domain

Export

Defined in

modules/domain.ts:36


calcHistogram

calcHistogram(array, numberOfBins?, property?): number[]

Calculates a histogram from array values

Parameters

NameTypeDefault valueDescription
arrayany[]undefinedInput array
numberOfBins?number4Number of bins to use
property?stringundefinedProperty to map by

Returns

number[]

The histogram

Export

Defined in

modules/distributions.ts:251


calcMax

calcMax(array, property?): number

Gets the max value in an array

Parameters

NameTypeDescription
arrayany[]Input array
property?stringProperty to map by

Returns

number

The maximum value in the array

Export

Defined in

modules/domain.ts:12


calcMean

calcMean(array, property?): number | undefined

Gets the mean value for an array

Parameters

NameTypeDescription
arrayany[]Input array
property?stringProperty to map by

Returns

number | undefined

The mean value

Export

Defined in

modules/averages.ts:100


calcMedian

calcMedian(array, property?): number | undefined

Gets an array median

Parameters

NameTypeDescription
arrayany[]Input array
property?stringThe property to map by

Returns

number | undefined

The resulting median

Export

Defined in

modules/averages.ts:16


calcMin

calcMin(array, property?): number

Gets the min value in an array

Parameters

NameTypeDescription
arrayany[]Input array
property?stringProperty to map

Returns

number

The minimum value in the array

Export

Defined in

modules/domain.ts:24


calcPercent

calcPercent(toCalc, total): number

Calculates the percentage of a value, given a total

Parameters

NameTypeDescription
toCalcnumberNumber to get percentage of
totalnumberTotal

Returns

number

Percentage of the total

Export

Defined in

modules/percentages.ts:22


calcQuartiles

calcQuartiles(array, property?): number, number, number

Gets the quartiles of an array

Parameters

NameTypeDescription
arrayany[]Input array
property?stringProperty to map by

Returns

number, number, number

The quartiles

Export

Defined in

modules/distributions.ts:227


calcStdDeviation

calcStdDeviation<T>(array, property?): number | undefined

Calculates the standard deviation in an array of numbers

Type parameters

Name
T

Parameters

NameType
arrayT[]
property?string

Returns

number | undefined

Export

Defined in

modules/averages.ts:155


calcSum

calcSum(array, property?): number

Gets the sum of the values in an array

Parameters

NameTypeDescription
arrayany[]Input array
property?stringProperty to map by

Returns

number

The sum

Export

Defined in

modules/operations.ts:12


calcVariance

calcVariance<T>(array, property?): number | undefined

Calculates the variance in an array of numbers

Type parameters

Name
T

Parameters

NameType
arrayT[]
property?string

Returns

number | undefined

Export

Defined in

modules/averages.ts:142


calcWeightedMean

calcWeightedMean(array, valueProperty, weightProperty): number

Gets the weighted mean for an array

Parameters

NameTypeDescription
arrayany[]Input array
valuePropertystringProperty to use for value
weightPropertystringProperty to use for weight

Returns

number

The weighted mean

Export

Defined in

modules/averages.ts:113


calcWeightedMedian

calcWeightedMedian(array, valueProperty, weightProperty): number

Gets an array weighted median

Parameters

NameTypeDescription
arrayany[]Input array
valuePropertystringThe property to use as value
weightPropertystringThe property to use as weight

Returns

number

The resulting median

Export

Defined in

modules/averages.ts:45


getMinMaxFromBucket

getMinMaxFromBucket(bucketLabel): number[]

Gets the min and max values for a calcDistribution bucket

Parameters

NameTypeDescription
bucketLabelstringThe bucket label

Returns

number[]

min, max

Export

Defined in

modules/distributions.ts:125


ruleOfThree

ruleOfThree(ifThis, isThis, thenThat): number

Performs a simple rule of three

Parameters

NameTypeDescription
ifThisnumberFirst param
isThisnumberFirst result
thenThatnumberSecond param

Returns

number

Second result

Export

Defined in

modules/percentages.ts:10

3.0.4

6 months ago

3.0.3

6 months ago

3.1.1

6 months ago

3.0.2

6 months ago

3.1.0

6 months ago

3.0.1

6 months ago

3.0.0

6 months ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.7.3

3 years ago

1.7.4

3 years ago

1.7.2

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.2

3 years ago

1.6.1

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago