Skip to content

Instantly share code, notes, and snippets.

@JRJurman
Last active December 23, 2015 07:19
Show Gist options
  • Select an option

  • Save JRJurman/6600305 to your computer and use it in GitHub Desktop.

Select an option

Save JRJurman/6600305 to your computer and use it in GitHub Desktop.
Someone asked how to get an odd or even value...
var cap = -Math.log(0);
var ultimateSwitchCase = "switch(x.toString())\n{";
for( var i=0; i < cap; i++ ) {
ultimateSwitchCase += "\tcase "+i+":\n\t\treturn \""+['even','odd'][i%2]+"\";\n";
}
ultimateSwitchCase += "}";
eval(ultimateSwitchCase);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment