The code is as follows
const {
aForm,
bForm,
eForm,
qForm,
} = this.form;
return (
aForm.isEditing ||
bForm.isEditing ||
eForm.isEditing ||
qForm.isEditing
);
Is there a way to refactor this?
Something like
const forms = pick(this.form, [
"aForm",
"bForm",
"eForm",
"qForm",
]);
Object.values(forms).map(f => f.isEditing).join("||") //Need to return boolean value.
2
Answers
I think you already have something close to what we (other viewers) would imagine. Here I’d suggest to use Array#some to achieve this. It allows you to check if one of the items matches the condition (a logical OR
||
).You have the opposite function which checks every value (so a logical AND
&&
).