Skip to content

Commit 55ec74a

Browse files
authored
Immutable error
`cart` is an Array. the ES6 spread operator can be used : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator
1 parent ff6fdc1 commit 55ec74a

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

README.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,7 @@ const addItemToCart = (cart, item) => {
602602
**Good:**
603603
```javascript
604604
const addItemToCart = (cart, item) => {
605-
const c = Object.assign({}, cart);
606-
607-
c.push({ item, date: Date.now() });
608-
609-
return c;
605+
return [...cart, { item, date : Date.now() }];
610606
};
611607
```
612608

0 commit comments

Comments
 (0)