math-helper-functions
Advanced tools
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 @@ * |
{ | ||
"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.<number></code> | ||
- [.calcHistogram(array, [numberOfBins], [property])](#MathFunctions.calcHistogram) ⇒ <code>Array.<number></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.<number></code> | ||
Calcs quartiles of data array | ||
**Kind**: static method of [<code>MathFunctions</code>](#MathFunctions) | ||
**Returns**: <code>Array.<number></code> - [min, mean, max] quartiles | ||
| Param | Type | Description | | ||
| ---------- | ------------------------------ | ----------------------------------------------------------------------------------- | | ||
| array | <code>Array.<any></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.<number></code> | ||
Calcs histogram from data array | ||
**Kind**: static method of [<code>MathFunctions</code>](#MathFunctions) | ||
**Returns**: <code>Array.<number></code> - Distribution data array | ||
| Param | Type | Default | Description | | ||
| -------------- | ------------------------------ | -------------- | ----------------------------------------------------------------------------------- | | ||
| array | <code>Array.<any></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 @@ |
23454
423
183
4
+ Addedjstat@^1.9.3
+ Addedjstat@1.9.6(transitive)