a statistics package in javascript
- lightweight, only 5.83kb
- easy to use
- both browser & node.js
- fast and efficient
npm install --save num-engine
<script src="https://unpkg.com/num-engine@1.0.0/output/num-engine.js"></script>
//in node.js
let NumEngine = require("num-engine");
let numEngine = new NumEngine([1,2,3,4,5]);
//in browsers
let numEngine = new NumEngine([1,2,3,4,5]);
let NumEngine = require("num-engine"); //browsers don't need this
let numEngine = new NumEngine([1,2,3,4,5],{
sorted:true //default is false
}); // config object is optional
{sorted:true} should be added for sorted array arguments to improve performance.
return the summation value of the array items
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.sum(); // 15
return the product of array items
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.product();
return the minimal value of array items
let numEngine = new NumEngine([1,2,3,4,5],{sorted:true});
let result = numEngine.min();
return the maximum value of array items
let numEngine = new NumEngine([1,2,3,4,5],{sorted:true});
let result = numEngine.max();
return the mean of array items
let numEngine = new NumEngine([1,2,3,4,5],{sorted:true});
let result = numEngine.mean();
return the geometric mean of array items
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.geometricMean();
return mode of array items
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.mode();
sort the current array in ascending order and also return the sorted array
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.sort();
sort the current array in descending order and also return the sorted array
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.reverseSort();
shuffle the current array and also return the shuffled array
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.shuffle();
return the median of aray items
let numEngine = new NumEngine([1,2,3,4,5]);
let result = numEngine.median();
divides the array into sub arrays with chunkSize length
let numEngine = new NumEngine([1,2,3,4,5,6]);
let result = numEngine.chunk(2);
/* result is [
[1,2],[3,4],[5,6]
]
*/
return the 1st ordered differentiated function of given function
NumEngine.differentiate(function(){
return Math.pow(2,2);
})
return a random integer
NumEngine.generateRandomInt(1,10);
return a random float number
NumEngine.generateRandomFloat(1,10);
return a random integer number array
NumEngine.generateRandomIntArray(5,1,10);
return a random float number array
NumEngine.generateRandomFloatArray(5,1,10);
return the variance of the given array
let numEngine = new NumEngine([1,2,3,4,5,6]);
let result = numEngine.variance();
return the standard deviation of the given array
let numEngine = new NumEngine([1,2,3,4,5,6]);
let result = numEngine.standardDeviation();
return the factorial value of a number
NumEngine.factorial(5);
return the min and max value of array items
let numEngine = new NumEngine([1,2,3,4,5,6]);
let result = numEngine.extent(); //[1,6]