bankers-math
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -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": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13318
410