Created
July 19, 2009 09:44
-
-
Save whalesalad/149867 to your computer and use it in GitHub Desktop.
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 characters
| Number.prototype.pluralize = function(singular, plural) { | |
| var a = '', b = 's'; | |
| if (singular && plural) { a = singular; b = plural; } | |
| return (this == 1) ? a : b; | |
| }; | |
| // Examples | |
| function cherries(numCherries) { | |
| alert('You have '+numCherries+' cherr'+numCherries.pluralize('y', 'ies')+' in mai bucket.'); | |
| }; | |
| cherries(3); // You have 3 cherries in mai bucket. | |
| cherries(1); // You have 1 cherry in mai bucket. | |
| // Combine all these little nuggets the grand finale! | |
| foo = 3; | |
| alert('You have '+foo.apnumber()+' cherr'+foo.pluralize('y', 'ies')+' in mai bucket.'); // You have one cherry in mai bucket. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment