static/js/util.js
/**
 * List categories and frequencies from a categorical column as weighted by a
 * numeric column.
 * @function listCatsW
 * @param {Array} arr1 - categorical column
 * @param {Array} arr2 - numeric column
 * @returns {[Object, number]} category to weighted frequency map, sum of
 * weights
 * @description NaN weights are skipped.
 */
List categories and frequencies from a categorical column as weighted by a
numeric column.
List categories and frequencies from a categorical column as weighted by a numeric column .
function listCatsW(arr1, arr2) {
  const res = {};
  const n = arr1.length;
  let cat, wt;
  let sum = 0;
  for (let i = 0; i < n; i++) {
    cat = arr1[i];
    wt = arr2[i];
    if (cat && wt === wt) {
      res[cat] = (res[cat] || 0) + wt;
    }
    sum += wt;
  }
  return [res, sum];
}
function listCatsW ( arr1 , arr2 ) { const res = { } ; const n = arr1 . length ; let cat , wt ; let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) { cat = arr1 [ i ] ; wt = arr2 [ i ] ; if ( cat && wt === wt ) { res [ cat ] = ( res [ cat ] || 0 ) + wt ; } sum += wt ; } return [ res , sum ] ; }
List categories and frequencies from a categorical column as weighted by a
 numeric column.
List categories and frequencies from a categorical column as weighted by a numeric column .