New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

31

index.js
const {max, min, mean, median, histogram} = require('d3-array');
const sum = require('lodash/sum');
const sumBy = require('lodash/sumBy');
const get = require('lodash/get');
const NumberHelper = require('number-helper-functions');
const {quartiles, histogram: jStatHistogram} = require('jstat');

@@ -140,2 +142,31 @@ /**

/**
* Calcs quartiles of data array
*
* @static
* @param {any[]} array Array to find quartiles of
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number[]} [min, mean, max] quartiles
* @memberof MathFunctions
*/
static calcQuartiles(array, property) {
const dataArray = property ? array.map((d) => get(d, property)) : array;
return quartiles(dataArray);
}
/**
* Calcs histogram from data array
*
* @static
* @param {any[]} array Array to get histogram from
* @param {number} [numberOfBins=4] Number of bins to distribute data
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number[]} Distribution data array
* @memberof MathFunctions
*/
static calcHistogram(array, numberOfBins = 4, property) {
const dataArray = property ? array.map((d) => get(d, property)) : array;
return jStatHistogram(dataArray, numberOfBins);
}
/**
* Performs a rule of three calculation

@@ -142,0 +173,0 @@ *

7

package.json
{
"name": "math-helper-functions",
"version": "1.1.0",
"version": "1.2.0",
"description": "Helper with misc. math functions such as sums, averages, max, min, etc",

@@ -20,3 +20,5 @@ "main": "index.js",

"percent",
"domain"
"domain",
"quartile",
"histogram"
],

@@ -28,2 +30,3 @@ "devDependencies": {

"d3-array": "^2.0.3",
"jstat": "^1.9.3",
"lodash": "^4.17.15",

@@ -30,0 +33,0 @@ "number-helper-functions": "^1.0.0"

@@ -17,2 +17,4 @@ <a name="MathFunctions"></a>

- [.calcDistribution(array, [numOfBins])](#MathFunctions.calcDistribution) ⇒ <code>object</code>
- [.calcQuartiles(array, [property])](#MathFunctions.calcQuartiles) ⇒ <code>Array.&lt;number&gt;</code>
- [.calcHistogram(array, [numberOfBins], [property])](#MathFunctions.calcHistogram) ⇒ <code>Array.&lt;number&gt;</code>
- [.ruleOfThree(ifThis, isThis, thenThat)](#MathFunctions.ruleOfThree) ⇒ <code>number</code>

@@ -139,2 +141,31 @@

<a name="MathFunctions.calcQuartiles"></a>
### MathFunctions.calcQuartiles(array, [property]) ⇒ <code>Array.&lt;number&gt;</code>
Calcs quartiles of data array
**Kind**: static method of [<code>MathFunctions</code>](#MathFunctions)
**Returns**: <code>Array.&lt;number&gt;</code> - [min, mean, max] quartiles
| Param | Type | Description |
| ---------- | ------------------------------ | ----------------------------------------------------------------------------------- |
| array | <code>Array.&lt;any&gt;</code> | Array to find quartiles of |
| [property] | <code>string</code> | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |
<a name="MathFunctions.calcHistogram"></a>
### MathFunctions.calcHistogram(array, [numberOfBins], [property]) ⇒ <code>Array.&lt;number&gt;</code>
Calcs histogram from data array
**Kind**: static method of [<code>MathFunctions</code>](#MathFunctions)
**Returns**: <code>Array.&lt;number&gt;</code> - Distribution data array
| Param | Type | Default | Description |
| -------------- | ------------------------------ | -------------- | ----------------------------------------------------------------------------------- |
| array | <code>Array.&lt;any&gt;</code> | | Array to get histogram from |
| [numberOfBins] | <code>number</code> | <code>4</code> | Number of bins to distribute data |
| [property] | <code>string</code> | | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |
<a name="MathFunctions.ruleOfThree"></a>

@@ -141,0 +172,0 @@

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