Skip to content

Instantly share code, notes, and snippets.

@evertonfraga
Created January 22, 2009 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evertonfraga/50492 to your computer and use it in GitHub Desktop.
Save evertonfraga/50492 to your computer and use it in GitHub Desktop.
/**
* 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