stats-lite
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "stats-lite", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A light statistical package that operates on numeric Arrays.", | ||
@@ -39,4 +39,4 @@ "main": "stats.js", | ||
"devDependencies": { | ||
"tape": "~1.0.4" | ||
"tape": "~2.4.0" | ||
} | ||
} |
@@ -43,2 +43,4 @@ stats-lite | ||
**NOTE**: This will impact some operations, e.g. `mean([null, 1, 2, 3])` will be calculated as `mean([1, 2, 3])`, (e.g. `6 / 3 = 2`, NOT `6 / 4 = 1.5`) | ||
`numbers(vals)` | ||
@@ -72,3 +74,3 @@ --- | ||
Calculate the [mode](http://en.wikipedia.org/wiki/Mode_(statistics)) average value of vals. | ||
Calculate the [mode](http://en.wikipedia.org/wiki/Mode_statistics) average value of vals. | ||
@@ -75,0 +77,0 @@ `variance(vals)` |
27
stats.js
@@ -13,7 +13,11 @@ module.exports.numbers = numbers | ||
function numbers(vals) { | ||
if (vals == null) return [] | ||
return vals.reduce(function (nums, v) { | ||
if (isNumber(v)) nums.push(+v) | ||
var nums = [] | ||
if (vals == null) | ||
return nums | ||
}, []) | ||
for (var i = 0; i < vals.length; i++) { | ||
if (isNumber(vals[i])) | ||
nums.push(+vals[i]) | ||
} | ||
return nums | ||
} | ||
@@ -27,3 +31,7 @@ | ||
vals = numbers(vals) | ||
return vals.reduce(function (total, val) { return total + val }, 0) | ||
var total = 0 | ||
for (var i = 0; i < vals.length; i++) { | ||
total += vals[i] | ||
} | ||
return total | ||
} | ||
@@ -65,3 +73,3 @@ | ||
}) | ||
var rank = Object.keys(dist).sort(function (a, b) { return dist[b] - dist[a] }) | ||
var rank = numbers(Object.keys(dist).sort(function (a, b) { return dist[b] - dist[a] })) | ||
mode = rank[0] | ||
@@ -79,4 +87,7 @@ if (dist[rank[1]] == dist[mode]) { | ||
var avg = mean(vals) | ||
diff = vals.map(function (v) { return Math.pow((v - avg), 2) }) | ||
return mean(diff) | ||
var diffs = [] | ||
for (var i = 0; i < vals.length; i++) { | ||
diffs.push(Math.pow((vals[i] - avg), 2)) | ||
} | ||
return mean(diffs) | ||
} | ||
@@ -83,0 +94,0 @@ |
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
6786
94
94