vendredi 28 août 2020

Repetitive if statement into one clean if statement inside a for loop

Considering the case of having to check a billion conditions, how could I reduce an ugly, repetitive if statement into a clean, elegant if statement by using a for loop. Example and documentation are very much appreciated!

Here's an example of the monstrosity I'm talking about:

 if (
        x === 0 && y === 1 ||
        x === 2 && y === 3 ||
        x === 4 && y === 5 ||
        x === 6 && y === 7 ||
        x === 8 && y === 9
      ) {
        // do somethig...
      }

Aucun commentaire:

Enregistrer un commentaire