utils.js

/**
 * @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 is(obj, type) {
  return Object.prototype.toString.call(obj) === "[object " + type + "]";
}

// All create* methods should log with this for consistent, useful data.
class Logger {
  start(name, params = {}) {
    console.groupCollapsed(name, params);
  }
  end(obj) {
    console.groupEnd();
    console.log("Result:", obj);
    return obj;
  }
}
export const logger = new Logger();