Suppose we have a data structure as follows:
products: {
'123': {
details: [
{
price: 45,
unitPrice: 0,
productName: 'apples'
}
]
}
}
Now, consider the following function:
function updateApplePrice(coefficient) {
const products = cloneDeep(vehicleProductSelector.getAllProducts(store.getStore().getState()));
let appleProduct;
Object.keys(products).forEach((productId) => {
const {
details
} = vehicleProducts[productId];
details.forEach((detail) => {
const {
price,
productName
} = detail;
if (productName === 'apples') {
detail.unitPrice = coefficient * detail.price;
appleProduct = products[productId];
}
});
});
return appleProduct;
}
The issue I am encountering is a linting error:
Assignment to property of function parameter
How can this issue be resolved without turning off the linting rule?
Many suggest using array destructuring to solve this problem, but it seems quite challenging given the complexity of this particular data structure.