Skip to content

Latest commit

 

History

History
27 lines (25 loc) · 660 Bytes

data_format.md

File metadata and controls

27 lines (25 loc) · 660 Bytes

Data Formatter

const totalCalc = function totalCalc(start, end, obj) {
  let total = obj[start];
  if (start < end) {
    for (var i = start; i <= end; i++) {
      total += obj[i];
    }
  }
  return total;
};

const dataFormatter = function dataFormatter(dataset, start, end) {
  const keys = Object.keys(dataset);
  let outputData = {};
  for (let i = 0; i < keys.length; i++) {
    let total = totalCalc(start, end, dataset[keys[i]]);
    outputData[nameToId[keys[i]]] = {
      totalNum: total,
      fillKey: fillCalc(total),
      totalStr: stringCalc(total),
    };
  }
  outputData["USA"] = { fillKey: "target"};
  return outputData;
};```