Skip to content
Advertisement

Repeated if else blocks

I have an if else construction that will sound absurd to you. Actually, I wrote a basic version of my real code so as not to prolong it. Is there anyone who can rationalize it?

JavaScript

Advertisement

Answer

You can use some early returns after finding a case for updating the data:

JavaScript

You can avoid the early returns by putting the data fetching stuff in some helper function instead of inside the decision logic:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement