Last active
December 14, 2015 17:19
-
-
Save fxg42/5121667 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
assert = require 'assert' | |
reverse = (str) -> | |
(str.split '').reverse().join '' | |
format = (num) -> | |
reverse (reverse num.toString()).replace /\d{3}(?=\d)/g, '$& ' | |
assert '1' is format 1 | |
assert '10' is format 10 | |
assert '100' is format 100 | |
assert '1 000' is format 1000 | |
assert '10 000' is format 10000 | |
assert '100 000' is format 100000 | |
assert '1 000 000' is format 1000000 | |
assert '10 000 000' is format 10000000 | |
assert '100 000 000' is format 100000000 | |
assert '1 000 000 000' is format 1000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment