DEV Community

Discussion on: JS Refactoring Combo: Introduce Object Destructuring

Collapse
 
pengeszikra profile image
Peter Vivo • Edited

Imho that for loop use too much side effect.

const countTotals = ({price:{amount, discount}}) => {
  totalAmount += amount - discount;
  totalDiscount += discount;  
};

const logSummary = ({price:{amount}, customer:{country, zipCode}}) => 
  logPurchase(country, zipCode, amount);

items.forEach(countTotals);
const logResults = items.map(logSummary);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
lgrammel profile image
Lars Grammel P42

The for loop is not the point, it is an example. This blog post is about describing a technique to introduce destructuring safely with automated refactorings in situations where you might want to.