I have an array of sizes that I’d like to reduce + chunk based on custom logic using ramda:
const sizes = [
{ size: 30 },
{ size: 10 },
{ size: 40 },
{ size: 20 },
{ size: 20 },
];
If the cumulative total exceeds the 50
threshold I would like to chunk them up, so that the result becomes:
const threshold = 50;
// 30 + 10 <= 50
// 40 <= 50
// 20 + 20 <= 50
const result = [40, 40, 40];
I’ve tried using reduceWhile
and splitWhen
but with no luck so far