Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JackDanger/247043 to your computer and use it in GitHub Desktop.

Select an option

Save JackDanger/247043 to your computer and use it in GitHub Desktop.
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