Last active
December 24, 2015 16:29
-
-
Save dillonforrest/6827931 to your computer and use it in GitHub Desktop.
Revisions
-
dillonforrest revised this gist
Oct 5, 2013 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,4 +11,6 @@ function contains(str, key) { var filtered = _.filter(coll, contains); ``` ~~The cool thing is the `~`. Apparently, when the '~' operator is used with integers other than `-1`, it evaluates to `false`. Otherwise, if the tilde is used with `-1`, it evaluates to `true`. MAGIC.~~ EDIT: I misspoke. The `~` will evaluate `-1` to `0`, which is falsy, and will evaluate all other integers to something other than 0, which all will be truthy. :) -
dillonforrest created this gist
Oct 4, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ I just came across this interesting bit of javascript, which I've paraphrased: ```javascript var _ = require('underscore'); var coll = require('./some/external/array'); function contains(str, key) { return ~str.indexOf(key); } var filtered = _.filter(coll, contains); ``` The cool thing is the `~`. Apparently, when the '~' operator is used with integers other than `-1`, it evaluates to `false`. Otherwise, if the tilde is used with `-1`, it evaluates to `true`. MAGIC.