The code is as follows
validateItems = (order, action) => {
let hasError = false;
orders.map(order => {
if (this.hasLineItemFormErrors(order, action)) hasError = true;
});
return hasError;
};
hasLineItemFormErrors = (order, action) => {
let hasError = false;
this.getLineItemsForms(order.id).map(form => {
if (form.hasError) hasError = true;
});
return hasError;
};
As you can see, i have to repeat the hasError variable on each method. Is there a more cleaner way to write this?
Something like
hasLineItemFormErrors = (order, action) => {
return this.getLineItemsForms(order.id).map(form => {
if (form.hasError) return true;
}); // When there are no errors, this will return formsArray, so the hasError variable in parent method becomes true
};