JSFiddle - React, Tailwind, and code Playground

by runjep

JavaScript

var months = ['Jan', 'Feb', 'Mar'];
var advisors = [{
  ID: 1,
  name: 'Bob'
}];
var emptyMonthArray = [0, 0, 0];
orders = [{
  advisorID: 1,
  period: new Date(),
  order: 3
}];

function getAdvisors() {
  var returnArray = [];
  advisors.forEach(function(a) {
    var returnObject = {
      name: a.name,
      monthData: emptyMonthArray.slice(0)
    };
    orders.forEach(function(o, i) {
      if (o.advisorID === a.ID) {
        returnObject.monthData[o.period.getMonth()] = o.order;
      }
    });
    returnArray.push(returnObject);
  });
  return returnArray;
}
console.log(getAdvisors());