-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpopulationStandardDeviation.js
More file actions
26 lines (23 loc) · 1.03 KB
/
populationStandardDeviation.js
File metadata and controls
26 lines (23 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const { populationVariance } = require('./populationVariance');
const { floatPrecise } = require('./floatPrecise');
const handleErrors = (params) => {
if (params.length <= 1) throw new Error('Must provide two or more parameters');
if (params.some(param => typeof param !== 'number')) {
throw new Error('One of your parameters does not evaluate to a number');
}
// JS can only safely represent and compare integers between
// Number.MAX_SAFE_INTEGER and Number.MAX_SAFE_INTEGER
if (params.some(param => param > Number.MAX_SAFE_INTEGER || param < Number.MIN_SAFE_INTEGER)) {
throw new Error('Cannot reliably test primality of numbers larger than 9,007,199,254,740,991 or smaller than -9,007,199,254,740,991');
}
};
/**
* This function calculates the population standard deviation
* @memberof variadic
* @author devNoiseConsulting
* @param {...*} params - One or more parameters.
*/
exports.populationStandardDeviation = (...params) => {
handleErrors(params);
return floatPrecise(Math.sqrt(populationVariance(...params)));
};