data = {
const keys = Object.keys(raw[0]);
const isTimestampKey = (k) => k.endsWith("Timestamp");
const timestampKeys = keys.filter(isTimestampKey);
return raw
.map((d) => {
return keys.reduce((obj, k) => {
if (timestampKeys.includes(k)) {
const newKey = k.replace("Timestamp", "On");
return { ...obj, [newKey]: new Date(d[k]) };
}
return {
...obj,
[k]: d[k]
};
}, {});
})
.map((d) => {
return { startedOn: new Date(d.startDateStr), ...d };
})
.sort((a, b) => b.revenue - a.revenue);
}