Last active
May 19, 2017 07:17
-
-
Save icyflame/8f9c30697b3c636cffcb48391c13c4b8 to your computer and use it in GitHub Desktop.
Replace commas according to the Indian numbering system
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
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