-
-
Save jaywhy13/5711891 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
Number.prototype.plural = function(){ | |
if(this > 1 || this == 0){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
String.prototype.pluralize_rules = function(){ | |
return [[new RegExp('$', 'gi'), 's']]; | |
} | |
String.prototype.pluralize = function(number){ | |
var str = this; | |
if(number.plural()){ | |
var str = this; | |
var rules = this.pluralize_rules(); | |
for(var r=0; r < rules.length; r++){ | |
if(str.match(rules[r][0])){ | |
str = str.replace(rules[r][0], rules[r][1]); | |
} | |
} | |
} | |
return str.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment