Taken from [Double exclamation points?][1]
Also: [What is the !! (not not) operator in JavaScript?][2]
#Double NOT Operator
This converts a value to a boolean and ensures a boolean type.
"foo" = "foo"
!"foo" = false
| function pad (n, width, z) { | |
| z = z || '0'; | |
| n = n + ''; | |
| while (n.length < width) { n = z + n; } | |
| return n; | |
| } |
| for (var i = 0; i < array.length; i++) (function (i, arrayElement) { | |
| // this will create a new variables i and arrayElement for each loop iteration | |
| // so we can use it in an async callback | |
| doSomeAsync(function callback () { | |
| console.log(i, arrayElement); | |
| }); | |
| }) (i, array[i]); |
| shuffle = function(v){ | |
| for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x); | |
| return v; | |
| }; |
| /** | |
| * Returns a random number between min and max | |
| */ | |
| function getRandomArbitary (min, max) { | |
| return Math.random() * (max - min) + min; | |
| } | |
| /** | |
| * Returns a random integer between min and max | |
| * Using Math.round() will give you a non-uniform distribution! |
| // http://crocodillon.com/blog/parsing-emoji-unicode-in-javascript | |
| var ranges = [ | |
| '\ud83c[\udf00-\udfff]', // U+1F300 to U+1F3FF | |
| '\ud83d[\udc00-\ude4f]', // U+1F400 to U+1F64F | |
| '\ud83d[\ude80-\udeff]' // U+1F680 to U+1F6FF | |
| ]; | |
| var regexp = new RegExp(ranges.join('|'), 'g'); |
Taken from [Double exclamation points?][1]
Also: [What is the !! (not not) operator in JavaScript?][2]
#Double NOT Operator
This converts a value to a boolean and ensures a boolean type.
"foo" = "foo"
!"foo" = false
Taken from [Tilde or the Floor? Javascript bitwise operators in Practice][1]
#Bitwise NOT - The ~ operator
Apart from "inverting the bits of its operand" bitwise NOT in JavaScript is actually very useful not only when it comes to binary. Firstly, it has a very interesting effect on integers - it converts the integer to -(N+1) value.
For example:
~2 === -3; //true
~1 === -2; //true
| // http://stackoverflow.com/a/5450113 | |
| // String prototyped | |
| String.prototype.repeat = function(count) { | |
| if (count < 1) return ''; | |
| var result = '', pattern = this.valueOf(); | |
| while (count > 0) { | |
| if (count & 1) result += pattern; | |
| count >>= 1, pattern += pattern; | |
| } |
| { | |
| "curly": false, | |
| "eqeqeq": true, | |
| "eqnull": true, | |
| "bitwise": true, | |
| "camelcase": false, | |
| "forin": true, | |
| "immed": true, | |
| "indent": 4, | |
| "latedef": true, |
| ALTER TABLE users | |
| ADD COLUMN `count` SMALLINT(6) NOT NULL AFTER `lastname`, | |
| ADD COLUMN `log` VARCHAR(12) NOT NULL AFTER `count`, | |
| ADD COLUMN `status` INT(10) UNSIGNED NOT NULL AFTER `log`; |