Hey guys, I'm having an issue with a reduce function.
Here's the function:
on second and further iterations the accumulator is undefined
Anyone know the reason why?
const { active, inProgress, upcoming } = momentBriefs.reduce(
(obj, brief, index) => {
console.log('index', index, 'brief', brief, obj);
if (brief.status === 'COMPLETE' && brief.startDate.isSame(todayMoment, 'week')) {
obj.active.push(brief);
} else if (brief.status === 'COMPLETE' && !brief.startDate.isSame(todayMoment, 'week')) {
obj.upcoming.push(brief);
} else if (brief.status === 'PUBLISHED') {
obj.inProgress.push(brief);
}
},
{
active: [],
inProgress: [],
upcoming: [],
},
);on second and further iterations the accumulator is undefined
Anyone know the reason why?
No any search results
You already invited:
1 Answers
Tim Callahan
Upvotes from:
Just add a return obj at the end of the if else chain
also, on an unrelated note, I thought this was talking about underwear initially hehe