Created
December 2, 2009 08:28
-
-
Save JackDanger/247043 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
| String.prototype.addMoneyCommas = function(){ | |
| return $.map( | |
| $.grep( | |
| // the input str, reversed, broken into sets of three | |
| this.split('').reverse().join('').split(/(...)/), | |
| // with the oddly-blank entries removed | |
| function(str){if(0 != str.length) return true} | |
| ), | |
| function(str){ | |
| // with the individual pieces then re-reversed | |
| return str.split('').reverse().join('') | |
| }) | |
| // and then _those_ pieces re-reversed | |
| .reverse() | |
| // joined by commas | |
| .join(",") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment