Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
math-helper-functions
Advanced tools
Helper with misc. math functions such as sums, averages, max, min, etc
Using npm, npm i math-helper-functions
.
Using yarn, yarn add math-helper-functions
.
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]
▸ calcDistribution(array
: any[], numOfBins?
: number): IDistribution
Calculates the distribution of an arrays values
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
numOfBins? | number | - |
Returns: IDistribution
The distribution
Defined in: modules/distributions.ts:22
▸ calcDomain(array
: any[], property?
: string): [number, number] | [any, any]
Gets the [min, max] value in an array
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
property? | string | - |
Returns: [number, number] | [any, any]
The domain
Defined in: modules/domain.ts:36
▸ calcHistogram(array
: any[], numberOfBins?
: number, property?
: string): number[]
Calculates a histogram from array values
export
Name | Type | Default value | Description |
---|---|---|---|
array | any[] | - | Input array |
numberOfBins | number | 4 | - |
property? | string | - | - |
Returns: number[]
The histogram
Defined in: modules/distributions.ts:68
▸ calcMax(array
: any[], property?
: string): number
Gets the max value in an array
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
property? | string | - |
Returns: number
The maximum value in the array
Defined in: modules/domain.ts:12
▸ calcMean(array
: any[], property?
: string): number | undefined
Gets the mean value for an array
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
property? | string | - |
Returns: number | undefined
The mean value
Defined in: modules/averages.ts:93
▸ calcMedian(array
: any[], property?
: string): number | undefined
Gets an array median
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
property? | string | - |
Returns: number | undefined
The resulting median
Defined in: modules/averages.ts:13
▸ calcMin(array
: any[], property?
: string): number
Gets the min value in an array
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
property? | string | - |
Returns: number
The minimum value in the array
Defined in: modules/domain.ts:24
▸ calcPercent(toCalc
: number, total
: number): number
Calculates the percentage of a value, given a total
export
Name | Type | Description |
---|---|---|
toCalc | number | Number to get percentage of |
total | number | Total |
Returns: number
Percentage of the total
Defined in: modules/percentages.ts:22
▸ calcQuartiles(array
: any[], property
: string): [number, number, number]
Gets the quartiles of an array
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
property | string | Property to map by |
Returns: [number, number, number]
The quartiles
Defined in: modules/distributions.ts:47
▸ calcSum(array
: any[], property?
: string): number
Gets the sum of the values in an array
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
property? | string | - |
Returns: number
The sum
Defined in: modules/operations.ts:12
▸ calcWeightedMean(array
: any[], valueProperty
: string, weightProperty
: string): number
Gets the weighted mean for an array
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
valueProperty | string | Property to use for value |
weightProperty | string | Property to use for weight |
Returns: number
The weighted mean
Defined in: modules/averages.ts:106
▸ calcWeightedMedian(array
: any[], valueProperty
: string, weightProperty
: string): number
Gets an array weighted median
export
Name | Type | Description |
---|---|---|
array | any[] | Input array |
valueProperty | string | The property to use as value |
weightProperty | string | The property to use as weight |
Returns: number
The resulting median
Defined in: modules/averages.ts:41
▸ ruleOfThree(ifThis
: number, isThis
: number, thenThat
: number): number
Performs a simple rule of three
export
Name | Type | Description |
---|---|---|
ifThis | number | First param |
isThis | number | First result |
thenThat | number | Second param |
Returns: number
Second result
Defined in: modules/percentages.ts:10
FAQs
Helper with misc. math functions such as sums, averages, max, min, etc
We found that math-helper-functions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.