return items.map(item => ({
...item,
score: Math.round((item.rate / 100) * 5)
}));
While this code snippet changes the score
value for each object in items
, you might be wondering about the use of ...item
.
What advantage does it provide?
Could it be achieved with this alternative approach?:
return items.map(item => ({
item.score: Math.round((item.rate / 100) * 5);
return item;
}));