Here is an example of an array:
[
{
id: '1',
task: 'Grocery shopping',
isImportant: true
},
{
id: '2',
task: 'Meeting',
isImportant: false
},
{
id: '3',
task: 'Presentation preparation',
isImportant: true
},
]
I want to reorganize this array based on the value of isImportant
into the following structure:
{
importantTasks: [
{
id: '1',
task: 'Grocery shopping',
isImportant: true
},
{
id: '3',
task: 'Presentation preparation',
isImportant: true
}
],
notImportantTasks: [
{
id: '2',
task: 'Meeting',
isImportant: false
}
]
}
While I am aware that I can use filter
and map
for this transformation, I am interested in leveraging reduce
in TypeScript for this particular scenario.