data_tidy = data.reduce((previousValue, currentValue) => {
const date = currentValue["YDate"];
const categories = [
"ACM",
"ACN",
"Star",
"PL",
"PX",
"RB",
"Part",
"DebPRC",
"DebIr",
"Deb",
"Err"
];
const other_total = categories
.filter((d) => d !== "Star")
.map((d) => currentValue[d])
.reduce((previousValue_other, currentValue_other) => {
return previousValue_other + currentValue_other;
}, 0);
const other = {
date,
category: "Other",
value: other_total
};
const star = {
date,
category: "Star",
value: currentValue["Star"]
};
return [other, star, ...previousValue];
}, [])