Created
April 11, 2016 09:54
-
-
Save stepankuzmin/e06369c3d91065c95b7081da341d1037 to your computer and use it in GitHub Desktop.
Format integer as string with spaces that separates thousands
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
| formatInt = (str) -> | |
| reducer = (acc, item, index) -> | |
| acc.push(' ') if index % 3 == 0 | |
| acc.push(item) | |
| acc | |
| str.toString() | |
| .split('') | |
| .reverse() | |
| .reduce(reducer, []) | |
| .slice(1) | |
| .reverse() | |
| .join('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment