OM
data = data.reduce(
(acc_, currentValue, index, array) => {
const prev = array[index + 1];
if (prev) {
const [prevKey_] = prev;
acc_[index] = {
...currentValue,
percentage: parseFloat(currentValue.count) * 100
/ parseFloat(acc_[prevKey_].count)
};
} else {
acc_[index] = currentValue;
}
return acc_;
},
{}
);
в мене data виклядає ось так
[
{
"stat": "Review",
"count": 9,
"color": "#a4c2f4",
"percentage": 9
},
{
"stat": "Pre-screen",
"count": 8,
"color": "#4a86e8",
"percentage": 8
},
{
"stat": "Rejected",
"count": 8,
"color": "#e06666",
"percentage": 8
},
{
"stat": "On hold",
"count": 7,
"color": "#ffffff",
"percentage": 7
},
{
"stat": "Interview",
"count": 7,
"color": "#ffe599",
"percentage": 7
},
{
"stat": "Test",
"count": 7,
"color": "#b4a7d6",
"percentage": 7
},
{
"stat": "Final Interview",
"count": 5,
"color": "#ffe599",
"percentage": 5
},
{
"stat": "OFFER",
"count": 5,
"color": "#b6d7a8",
"percentage": 5
},
{
"stat": "Hired",
"count": 3,
"color": "#6aa84f",
"percentage": 3
},
{
"stat": "WR",
"count": 1,
"color": "#e06666",
"percentage": 1
}
]
чомусь reduce матюкається, каже
TypeError: Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.