Skip to content

Instantly share code, notes, and snippets.

@stepankuzmin
Created April 11, 2016 09:54
Show Gist options
  • Save stepankuzmin/e06369c3d91065c95b7081da341d1037 to your computer and use it in GitHub Desktop.
Save stepankuzmin/e06369c3d91065c95b7081da341d1037 to your computer and use it in GitHub Desktop.
Format integer as string with spaces that separates thousands
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