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.2.0 to 1.3.0

26

index.js

@@ -5,3 +5,3 @@ const {max, min, mean, median, histogram} = require('d3-array');

const get = require('lodash/get');
const NumberHelper = require('number-helper-functions');
const {processNumber} = require('number-helper-functions');
const {quartiles, histogram: jStatHistogram} = require('jstat');

@@ -90,3 +90,3 @@

/**
* Returns mean value in array
* Returns mean value of array
*

@@ -106,2 +106,21 @@ * @static

/**
* Returns weighted mean of array
*
* @static
* @param {object[]} array Array to find weighted mean of
* @param {string} valueProperty Property to use for array item value
* @param {string} weightProperty Property to use for array item weight
* @returns {number} Weighted mean
* @memberof MathFunctions
*/
static calcWeightedMean(array, valueProperty, weightProperty) {
if (!valueProperty || !weightProperty) {
throw new Error('Both valueProperty and weightProperty params are required');
}
const totalWeight = MathFunctions.calcSum(array, weightProperty);
const weightedValues = array.map((d) => d[valueProperty] * d[weightProperty]);
return MathFunctions.calcSum(weightedValues) / totalWeight;
}
/**
* Calculate percentage using rule of three

@@ -129,4 +148,3 @@ *

static calcDistribution(array, numOfBins) {
const numHelper = new NumberHelper();
const numArray = array.map((d) => numHelper.processNumber(d));
const numArray = array.map((d) => processNumber(d));
const hist = numOfBins ? histogram().thresholds(numOfBins) : histogram();

@@ -133,0 +151,0 @@ const dist = hist(numArray);

6

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

@@ -19,2 +19,4 @@ "main": "index.js",

"max",
"mean",
"weighted",
"percent",

@@ -32,3 +34,3 @@ "domain",

"lodash": "^4.17.15",
"number-helper-functions": "^1.0.0"
"number-helper-functions": "^2.1.0"
},

@@ -35,0 +37,0 @@ "prettier": {

@@ -15,2 +15,3 @@ <a name="MathFunctions"></a>

- [.calcMean(array, [property])](#MathFunctions.calcMean) ⇒ <code>Number</code>
- [.calcWeightedMean(array, valueProperty, weightProperty)](#MathFunctions.calcWeightedMean) ⇒ <code>number</code>
- [.calcPercent(toCalc, total)](#MathFunctions.calcPercent) ⇒ <code>Number</code>

@@ -103,3 +104,3 @@ - [.calcDistribution(array, [numOfBins])](#MathFunctions.calcDistribution) ⇒ <code>object</code>

Returns mean value in array
Returns mean value of array

@@ -114,2 +115,17 @@ **Kind**: static method of [<code>MathFunctions</code>](#MathFunctions)

<a name="MathFunctions.calcWeightedMean"></a>
### MathFunctions.calcWeightedMean(array, valueProperty, weightProperty) ⇒ <code>number</code>
Returns weighted mean of array
**Kind**: static method of [<code>MathFunctions</code>](#MathFunctions)
**Returns**: <code>number</code> - Weighted mean
| Param | Type | Description |
| -------------- | --------------------------------- | ------------------------------------- |
| array | <code>Array.&lt;object&gt;</code> | Array to find weighted mean of |
| valueProperty | <code>string</code> | Property to use for array item value |
| weightProperty | <code>string</code> | Property to use for array item weight |
<a name="MathFunctions.calcPercent"></a>

@@ -116,0 +132,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