I have the following code. Is it possible to run reduce only once to change the key names? In the example below, I run the reduce function twice. How this can become more efficient? Can this be done with one iteration?
const newArrayOfObj = rows.map(row => {
row = Object.keys(row).reduce(
(a, key) =>
({
...a,
[key === 'redirects' ? 'clicks' : key]: row[key],
}),
{},
);
row = Object.keys(row).reduce(
(a, key) =>
({
...a,
[key === 'tags' ? 'external impressions' : key]: row[key],
}),
{}
);
return row;
});
return newArrayOfObj;
}