Skip to content

Instantly share code, notes, and snippets.

@dalmaer
Created May 27, 2011 04:46
Show Gist options
  • Save dalmaer/994655 to your computer and use it in GitHub Desktop.
Save dalmaer/994655 to your computer and use it in GitHub Desktop.
// Use ~ with indexOf to test presence
hasAnF="This sentence has an f.".indexOf("f")>=0 // before
hasAnF=~"This sentence has an f.".indexOf("f") // after
// Both of these operator combos will floor numbers (note that since ~ has lower precedence than |, they are not identical).
rand10=Math.floor(Math.random()*10) // before
rand10=0|Math.random()*10 // after
// This is equivalent to A*Math.pow(10,B).
million=1000000 // before
million=1e6 // after
// Did you know that strings have a .link() method?
html="<a href='"+url+"'>"+text+"</a>" // before
html=text.link(url) // after
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment