Skip to content

Instantly share code, notes, and snippets.

@tonyonodi
Created March 3, 2017 02:05
Show Gist options
  • Save tonyonodi/b483b2340a7d397b8042e25fdf3c4291 to your computer and use it in GitHub Desktop.
Save tonyonodi/b483b2340a7d397b8042e25fdf3c4291 to your computer and use it in GitHub Desktop.
Add commas to numbers
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