Created
March 3, 2017 02:05
-
-
Save tonyonodi/b483b2340a7d397b8042e25fdf3c4291 to your computer and use it in GitHub Desktop.
Add commas to numbers
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
const insertCommas = number => number | |
.toString() | |
.split("") | |
.reduce( | |
(acc, curr, i, arr) => (arr.length - i) % 3 === 0 | |
? `${acc},${curr}` | |
: `${acc}${curr}` | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment