Created
January 22, 2009 10:28
-
-
Save evertonfraga/50492 to your computer and use it in GitHub Desktop.
This file contains 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 characters
/** | |
* Some cool JavaScript prototypes. | |
* Author: Everton Fraga <everton{shift+2}kindaconnected.com> | |
* | |
*/ | |
/* | |
* Number.times:Array | |
* Param: int n | |
* Example: (9).times(6); // returns: [9, 9, 9, 9, 9, 9] | |
*/ | |
Number.prototype.times = function(n){ | |
arr = []; | |
for(i=0; i<n; i++) arr.push(this.valueOf()); | |
return arr; | |
}; | |
/* | |
* Number.isOdd: | |
* Forget the 'grandpa' way of verifying odd/even numbers: (5 % 2) == 1 | |
* Bitwise operator rulez! | |
*/ | |
Number.prototype.isOdd = function(){ | |
return !!(this.valueOf() & 1); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment