/**
* @module utils
* @description A set of utilities
*/
/**
* Sum the values of the array (must be numbers).
*
* @static
* @method sum
*
* @param array {Array} array of number values
* @return {Number} the sum of the values in the array
*/
export function sum(array) {
return (array || []).reduce(function (memo, num) {
if (typeof num === "number") {
memo += num;
}
return memo;
}, 0);
}
export function bounded(n, min, max) {
max = max || Number.MAX_VALUE; // have to have a min
return n < min ? min : n > max ? max : n;
}
export function is(obj, type) {
return Object.prototype.toString.call(obj) === "[object " + type + "]";
}
// All create* methods should log with this for consistent, useful data.
export var logger = {
start: (name, params = {}) => {
console.group(name, params);
},
end: (obj) => {
console.groupEnd();
return obj;
},
};