Skip to content

Instantly share code, notes, and snippets.

@icyflame
Last active May 19, 2017 07:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icyflame/8f9c30697b3c636cffcb48391c13c4b8 to your computer and use it in GitHub Desktop.
Save icyflame/8f9c30697b3c636cffcb48391c13c4b8 to your computer and use it in GitHub Desktop.
Replace commas according to the Indian numbering system
t = [1, 12, 123, 1234, 12345,
123456, 1234567, 12345678,
123456789, 1234567890,
12345678901, 123456789012];
function convert(x) {
return x.toString().substr()
.replace(/\B(?=\d{3}$)/g, ",")
.replace(/\B(?=(\d{2})+(?!\d),)/g, ",")
};
console.log(t.map(convert));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment