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.0 to 1.6.1

9

index.js

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

// Prevent undefined problems
if (!valueProperty || !weightProperty) {
throw new Error('Both valueProperty and weightProperty params are required');
}
if (array.length === 0) {

@@ -136,5 +139,7 @@ return 0;

if (weight === midpoint) {
return (sortedArray[index - 1].value + sortedArray[index].value) / 2;
const prevItem = get(sortedArray[index - 1], 'value', 0);
const currItem = get(sortedArray[index], 'value', 0);
return (prevItem + currItem) / 2;
} else {
return sortedArray[index - 1].value;
return get(sortedArray[index - 1], 'value', 0);
}

@@ -141,0 +146,0 @@ }

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

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -148,2 +148,8 @@ const MathFunctions = require('../index');

});
test('If a value prop or weight prop is not provided for calcWeightedMean method, an error should be thrown', () => {
expect(() => {
MathFunctions.calcWeightedMean([], 'something');
}).toThrow();
});
});

@@ -160,2 +166,14 @@

test('The weighted median of an empty array should be 0', () => {
expect(MathFunctions.calcWeightedMedian([], 'value', 'weight')).toStrictEqual(0);
});
test('The weighted median of an array with one element should be that same value', () => {
expect(MathFunctions.calcWeightedMedian(
weightedSimpleArray.slice(0, 1),
'value',
'weight'
)).toStrictEqual(weightedSimpleArray[0].value);
});
test('The weighted median of elements with different weight should not be the median of the array values', () => {

@@ -171,2 +189,8 @@ expect(MathFunctions.calcWeightedMedian(

});
test('If a value prop or weight prop is not provided for calcWeightedMedian method, an error should be thrown', () => {
expect(() => {
MathFunctions.calcWeightedMedian([], 'something');
}).toThrow();
});
});

@@ -173,0 +197,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