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.3.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
149
decreased by-62.75%
Maintainers
1
Weekly downloads
 
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

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


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


calcDiff

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

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

export

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

Returns: number

Absolute difference between the max and min of an array


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


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


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


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


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


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


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


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


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


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


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

Keywords

FAQs

Package last updated on 14 Sep 2022

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