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 - npm Package Compare versions

Comparing version 1.6.2 to 1.7.0

68

index.js

@@ -1,2 +0,2 @@

const {sum, max, min, mean, median, histogram} = require('d3-array');
const {sum, max, min, mean, median, extent, histogram} = require('d3-array');
const get = require('lodash/get');

@@ -13,13 +13,13 @@

/**
* Gets args for functions
* Gets array of values from possibly complex arrays
*
* @private
* @static
* @private
* @param {Array} array
* @param {string} property
* @returns {Array}
* @param {string} [property]
* @return {Array}
* @memberof MathFunctions
*/
static getArgs(array, property) {
return property ? [array, (d) => get(d, property)] : [array];
static _getSimpleArray(array, property) {
return property ? array.map((d) => get(d, property)) : array;
}

@@ -32,8 +32,7 @@

* @param {Array} array Array to find max value of
* @param {string} [property=null] Property name to iterate
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number} Max array value
*/
static calcMax(array, property = null) {
const args = MathFunctions.getArgs(array, property);
return max(...args);
static calcMax(array, property) {
return max(MathFunctions._getSimpleArray(array, property));
}

@@ -46,8 +45,7 @@

* @param {Array} array Array to find sum of
* @param {string} [property=null] Property name to iterate
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number} Sum of array values
*/
static calcSum(array, property = null) {
const args = MathFunctions.getArgs(array, property);
return sum(...args);
static calcSum(array, property) {
return sum(MathFunctions._getSimpleArray(array, property));
}

@@ -59,8 +57,7 @@

* @param {Array} array Array to find min value of
* @param {string} [property=null] Property name to iterate
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number} Min array value
*/
static calcMin(array, property = null) {
const args = MathFunctions.getArgs(array, property);
return min(...args);
static calcMin(array, property) {
return min(MathFunctions._getSimpleArray(array, property));
}

@@ -71,11 +68,9 @@

*
* @param {string[]|number[]} array Array to calc domain of
* @param {string} [property=null] Property name to iterate
* @param {Array} array Array to calc domain of
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number[]} Min and max values in array
*/
static calcDomain(array, property = null) {
return [
MathFunctions.calcMin(array, property),
MathFunctions.calcMax(array, property),
];
static calcDomain(array, property) {
const simpleArray = MathFunctions._getSimpleArray(array, property);
return extent(simpleArray);
}

@@ -88,9 +83,8 @@

* @param {Array} array Array to find median of
* @param {string} [property=null] Property name to iterate
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number} Median of an array
* @memberof MathFunctions
*/
static calcMedian(array, property = null) {
const args = MathFunctions.getArgs(array, property);
return median(...args);
static calcMedian(array, property) {
return median(MathFunctions._getSimpleArray(array, property));
}

@@ -157,9 +151,8 @@

* @param {Array} array Array to find mean of
* @param {string} [property=null] Property name to iterate
* @param {string} [property] Property to access in object arrays. Supports nested properties (ex: 'propA.propB')
* @returns {number} Mean of an array
* @memberof MathFunctions
*/
static calcMean(array, property = null) {
const args = MathFunctions.getArgs(array, property);
return mean(...args);
static calcMean(array, property) {
return mean(MathFunctions._getSimpleArray(array, property));
}

@@ -240,7 +233,4 @@

const len = array.length;
const copy = array
.map(function(d) {
return property ? get(d, property) : d;
})
.sort((a, b) => a - b);
const simpleArray = MathFunctions._getSimpleArray(array, property);
const copy = simpleArray.sort((a, b) => a - b);
return [

@@ -247,0 +237,0 @@ copy[Math.round(len / 4) - 1],

{
"name": "math-helper-functions",
"version": "1.6.2",
"version": "1.7.0",
"description": "Helper with misc. math functions such as sums, averages, max, min, etc",

@@ -37,5 +37,7 @@ "main": "index.js",

"prettier": {
"arrowParens": "always",
"bracketSpacing": false,
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"semi": true,
"singleQuote": true,

@@ -42,0 +44,0 @@ "eslintIntegration": true

@@ -39,6 +39,6 @@ <a name="MathFunctions"></a>

| Param | Type | Default | Description |
| ---------- | ------------------- | ----------------- | -------------------------- |
| array | <code>Array</code> | | Array to find max value of |
| [property] | <code>string</code> | <code>null</code> | Property name to iterate |
| Param | Type | Description |
| ---------- | ------------------- | ----------------------------------------------------------------------------------- |
| array | <code>Array</code> | Array to find max value of |
| [property] | <code>string</code> | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |

@@ -54,6 +54,6 @@ <a name="MathFunctions.calcSum"></a>

| Param | Type | Default | Description |
| ---------- | ------------------- | ----------------- | ------------------------ |
| array | <code>Array</code> | | Array to find sum of |
| [property] | <code>string</code> | <code>null</code> | Property name to iterate |
| Param | Type | Description |
| ---------- | ------------------- | ----------------------------------------------------------------------------------- |
| array | <code>Array</code> | Array to find sum of |
| [property] | <code>string</code> | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |

@@ -69,6 +69,6 @@ <a name="MathFunctions.calcMin"></a>

| Param | Type | Default | Description |
| ---------- | ------------------- | ----------------- | -------------------------- |
| array | <code>Array</code> | | Array to find min value of |
| [property] | <code>string</code> | <code>null</code> | Property name to iterate |
| Param | Type | Description |
| ---------- | ------------------- | ----------------------------------------------------------------------------------- |
| array | <code>Array</code> | Array to find min value of |
| [property] | <code>string</code> | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |

@@ -84,6 +84,6 @@ <a name="MathFunctions.calcDomain"></a>

| Param | Type | Default | Description |
| ---------- | ---------------------------------------------------------------------- | ----------------- | ------------------------ |
| array | <code>Array.&lt;string&gt;</code> \| <code>Array.&lt;number&gt;</code> | | Array to calc domain of |
| [property] | <code>string</code> | <code>null</code> | Property name to iterate |
| Param | Type | Description |
| ---------- | ------------------- | ----------------------------------------------------------------------------------- |
| array | <code>Array</code> | Array to calc domain of |
| [property] | <code>string</code> | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |

@@ -99,6 +99,6 @@ <a name="MathFunctions.calcMedian"></a>

| Param | Type | Default | Description |
| ---------- | ------------------- | ----------------- | ------------------------ |
| array | <code>Array</code> | | Array to find median of |
| [property] | <code>string</code> | <code>null</code> | Property name to iterate |
| Param | Type | Description |
| ---------- | ------------------- | ----------------------------------------------------------------------------------- |
| array | <code>Array</code> | Array to find median of |
| [property] | <code>string</code> | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |

@@ -129,6 +129,6 @@ <a name="MathFunctions.calcWeightedMedian"></a>

| Param | Type | Default | Description |
| ---------- | ------------------- | ----------------- | ------------------------ |
| array | <code>Array</code> | | Array to find mean of |
| [property] | <code>string</code> | <code>null</code> | Property name to iterate |
| Param | Type | Description |
| ---------- | ------------------- | ----------------------------------------------------------------------------------- |
| array | <code>Array</code> | Array to find mean of |
| [property] | <code>string</code> | Property to access in object arrays. Supports nested properties (ex: 'propA.propB') |

@@ -135,0 +135,0 @@ <a name="MathFunctions.calcWeightedMean"></a>

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