Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

math-helper-functions

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

math-helper-functions

Helper with misc. math functions such as sums, averages, max, min, etc

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

  • calcDistribution
  • calcDomain
  • calcHistogram
  • calcMax
  • calcMean
  • calcMedian
  • calcMin
  • calcPercent
  • calcQuartiles
  • calcSum
  • calcWeightedMean
  • calcWeightedMedian
  • ruleOfThree

Functions

calcDistribution

calcDistribution(array: any[], numOfBins?: number): IDistribution

Calculates the distribution of an arrays values

export

Parameters:
NameTypeDescription
arrayany[]Input array
numOfBins?number-

Returns: IDistribution

The distribution

Defined in: modules/distributions.ts:22


calcDomain

calcDomain(array: any[], property?: string): [number, number] | [any, any]

Gets the [min, max] value in an array

export

Parameters:
NameTypeDescription
arrayany[]Input array
property?string-

Returns: [number, number] | [any, any]

The domain

Defined in: modules/domain.ts:36


calcHistogram

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

Calculates a histogram from array values

export

Parameters:
NameTypeDefault valueDescription
arrayany[]-Input array
numberOfBinsnumber4-
property?string--

Returns: number[]

The histogram

Defined in: modules/distributions.ts:68


calcMax

calcMax(array: any[], property?: string): number

Gets the max value in an array

export

Parameters:
NameTypeDescription
arrayany[]Input array
property?string-

Returns: number

The maximum value in the array

Defined in: modules/domain.ts:12


calcMean

calcMean(array: any[], property?: string): number | undefined

Gets the mean value for an array

export

Parameters:
NameTypeDescription
arrayany[]Input array
property?string-

Returns: number | undefined

The mean value

Defined in: modules/averages.ts:93


calcMedian

calcMedian(array: any[], property?: string): number | undefined

Gets an array median

export

Parameters:
NameTypeDescription
arrayany[]Input array
property?string-

Returns: number | undefined

The resulting median

Defined in: modules/averages.ts:13


calcMin

calcMin(array: any[], property?: string): number

Gets the min value in an array

export

Parameters:
NameTypeDescription
arrayany[]Input array
property?string-

Returns: number

The minimum value in the array

Defined in: modules/domain.ts:24


calcPercent

calcPercent(toCalc: number, total: number): number

Calculates the percentage of a value, given a total

export

Parameters:
NameTypeDescription
toCalcnumberNumber to get percentage of
totalnumberTotal

Returns: number

Percentage of the total

Defined in: modules/percentages.ts:22


calcQuartiles

calcQuartiles(array: any[], property: string): [number, number, number]

Gets the quartiles of an array

export

Parameters:
NameTypeDescription
arrayany[]Input array
propertystringProperty to map by

Returns: [number, number, number]

The quartiles

Defined in: modules/distributions.ts:47


calcSum

calcSum(array: any[], property?: string): number

Gets the sum of the values in an array

export

Parameters:
NameTypeDescription
arrayany[]Input array
property?string-

Returns: number

The sum

Defined in: modules/operations.ts:12


calcWeightedMean

calcWeightedMean(array: any[], valueProperty: string, weightProperty: string): number

Gets the weighted mean for an array

export

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

Returns: number

The weighted mean

Defined in: modules/averages.ts:106


calcWeightedMedian

calcWeightedMedian(array: any[], valueProperty: string, weightProperty: string): number

Gets an array weighted median

export

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

Returns: number

The resulting median

Defined in: modules/averages.ts:41


ruleOfThree

ruleOfThree(ifThis: number, isThis: number, thenThat: number): number

Performs a simple rule of three

export

Parameters:
NameTypeDescription
ifThisnumberFirst param
isThisnumberFirst result
thenThatnumberSecond param

Returns: number

Second result

Defined in: modules/percentages.ts:10

Keywords

FAQs

Package last updated on 13 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc