Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bankers-math

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bankers-math - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

56

Banker.js

@@ -14,2 +14,3 @@ // EU on Bankers' rounding: https://ec.europa.eu/economy_finance/publications/pages/publication1224_en.pdf

const DIFF_TEMP = { min: 0, max: 0, fix: 0, percent: 0 };
const DEF_ANALYSE = { min: 0, max: 0, avg: 0, variance: 0, sum: 0 };

@@ -44,3 +45,18 @@ let Services = {

},
variance(list, decimalPlaces) {
const squareDiffs = list.map((value) => {
const diff = value - avg;
return diff * diff;
});
return Services.toFixedNumber(
Math.sqrt(
squareDiffs.reduce((acc, current) => acc + current, 0) /
list.length,
),
decimalPlaces,
);
},
analyseValues(list, decimalPlaces = 6) {
if (!(list.length >= 0)) return DEF_ANALYSE;
let sum = Services.toFixedNumber(Services.sum(list), decimalPlaces);

@@ -52,16 +68,3 @@ let avg = Services.toFixedNumber(

let variance = 0;
if (list.length > 0) {
const squareDiffs = list.map((value) => {
const diff = value - avg;
return diff * diff;
});
variance = Services.toFixedNumber(
Math.sqrt(
squareDiffs.reduce((acc, current) => acc + current, 0) /
list.length,
),
decimalPlaces,
);
}
let variance = Services.variance(list, decimalPlaces);

@@ -72,7 +75,28 @@ return {

variance,
min: list.length > 0 ? Math.min(...list) : 0,
max: list.length > 0 ? Math.max(...list) : 0,
min: Math.min(...list),
max: Math.max(...list),
};
},
aggregateAnalysedValues(list, decimalPlaces = 6) {
if (!(list.length >= 0)) return DEF_ANALYSE;
return {
sum: Services.toFixedNumber(
Services.sum(list.map((d) => d.sum)),
decimalPlaces,
),
avg: Services.toFixedNumber(
Services.sum(list.map((d) => d.avg)) / list.length,
decimalPlaces,
),
variance: Services.variance(
list.map((d) => d.variance),
decimalPlaces,
),
min: Math.min(...list.map((d) => d.min)),
max: Math.max(...list.map((d) => d.max)),
};
},
defined(value) {

@@ -79,0 +103,0 @@ return value !== undefined && value !== null;

{
"name": "bankers-math",
"version": "0.2.6",
"version": "0.2.7",
"description": "Helper function for Bankers' calculus",

@@ -5,0 +5,0 @@ "keywords": [

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