Created
April 29, 2020 01:42
-
-
Save jzevin/c86ed5fe7a1188fd4483ceb4b4937e61 to your computer and use it in GitHub Desktop.
JavaScript one liner for adding commas to a number
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
`3343453545`.split('').sort(()=>-1).reduceRight((p,c,i)=>i&&i%3===0?p+=c+',':p+=c,'') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was thinking how i could do this with one line ES-2016 syntax
Got any ideas or improvements?
here's the prettier version: