I have some loop like this
for (let i = 0, l = this.documents.length; i < l; ++i) {
if (item.text !== null) {
if (this.documents[i].text === item.text) {
this.documents[i].mandatory = !item.mandatory;
break;
}
} else {
if (this.documents[i].code === item.code) {
this.documents[i].mandatory = !item.mandatory;
break;
}
}
}
The problem I have is that I have code smell, with so many if, else, can somebody help me to make it shorter and reusable? Thanks
l = this.documents.lengthis not a useful optimisation since about IE7 or 8. Browsers and engines should already implement this for you.