[Solved] Can someone help me with this algorithm?


You could use reduce for this kind of thing, here is an example:

var calendar = {Q1 : {P1 : {WK1 : {start: '1/1/2018',end: '1/7/2018'},WK2 : {start: '1/8/2018',end: '1/14/2018'}},P2 : {WK3 : {start: '1/15/2018',end: '1/21/2018'}}},Q2 : {P3 : {WK5 : {start: '2/1/2018',end: '2/7/2018'},WK6 : {start: '2/8/2018',end: '2/14/2018'}},P4 : {WK7 : {start: '2/15/2018',end: '2/21/2018'}}}};

var result = Object.keys(calendar).reduce((a, c) => {
  Object.keys(calendar[c]).forEach(period => {
     let weeks = Object.values(calendar[c][period]);
     let firstWeek = weeks[0];
     let lastWeek = weeks[weeks.length - 1];
     a.push({quarter: c, period: period, start_date: firstWeek.start, end_date: lastWeek.end});
  });
  return a;
}, []);

console.log(result);

1

solved Can someone help me with this algorithm?