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

calc-stats

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calc-stats - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

44

calc-stats.js

@@ -9,2 +9,3 @@ const { getOrCreateIterator } = require("iter-fun");

noData = undefined,
filter = undefined,
calcHistogram = true,

@@ -22,3 +23,3 @@ calcMax = true,

let needCount = calcMean || calcMedian;
let needCount = calcMean || calcMedian || typeof filter === "function";
let needHistogram = calcHistogram || calcMedian || calcMode || calcModes;

@@ -28,2 +29,3 @@ let needSum = calcSum || calcMean;

let count = 0;
let index = 0;
let min;

@@ -34,15 +36,35 @@ let max;

const step = value => {
if (value !== noData) {
if (needCount) count++;
if (calcMin && (min === undefined || value < min)) min = value;
if (calcMax && (max === undefined || value > max)) max = value;
if (needSum) sum += value;
if (needHistogram) {
if (value in histogram) histogram[value].ct++;
else histogram[value] = { n: value, ct: 1 };
}
// after it processes filtering
const process = value => {
if (needCount) count++;
if (calcMin && (min === undefined || value < min)) min = value;
if (calcMax && (max === undefined || value > max)) max = value;
if (needSum) sum += value;
if (needHistogram) {
if (value in histogram) histogram[value].ct++;
else histogram[value] = { n: value, ct: 1 };
}
};
let step;
if (typeof noData === "number" && typeof filter === "function") {
step = value => {
index++;
if (value !== noData && filter({ count, index, value }) === true) {
process(value);
}
};
} else if (typeof noData === "number") {
step = value => value !== noData && process(value);
} else if (typeof filter === "function") {
step = value => {
index++;
if (filter({ count, index, value }) === true) {
process(value);
}
};
} else {
step = process;
}
const finish = () => {

@@ -49,0 +71,0 @@ const results = {};

{
"name": "calc-stats",
"version": "0.3.2",
"version": "0.3.3",
"description": "Memory-Aware Statistical Calculations",

@@ -5,0 +5,0 @@ "main": "calc-stats.js",

@@ -65,2 +65,19 @@ # calc-stats

## filtering
If you want to ignore some values, you can use a filter function:
```js
const results = calcStats(data, {
filter: ({ index, value }) => {
// ignore the first 10 numbers
if (index < 10) return false;
// ignore any negative numbers
// or values greater than 100
if (value < 0 && value > 100) return false;
return true;
}
})
```
## specify calculations

@@ -67,0 +84,0 @@ If you only care about specific statistics, you can configure calcStats through an options object:

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