Skip to content

Instantly share code, notes, and snippets.

@sinsunsan
Created August 5, 2019 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinsunsan/bc176b1d845d5f7dc14d63e946b1278d to your computer and use it in GitHub Desktop.
Save sinsunsan/bc176b1d845d5f7dc14d63e946b1278d to your computer and use it in GitHub Desktop.
alternative switch not evaluating the value of switched variable
lines.forEach((line, index) => {
switch (true) {
// the this.isACondition return true and will be evaluated o not otherwise won't be
case this.isACondition(line):
doSomething++;
break;
case this.isAnOtherCondition(line):
doElseThing++;
break;
case this.somethingElseThatReturnTrueOrFalse(line, index):
doAnotherthing++;
break;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment