Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions collections/number/add-commas-to-number.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
~~~ javascript
const addCommas = (num) => (!num) ? null : num.toString().split('.').map((n,i) => (i === 0) ? n.replace(/\B(?=(\d{3})+(?!\d))/g, ',') : n).join('.');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the check !num? All of snippets assume that users pass valid parameters. So it looks like

const addCommas = (num) => [...`${num}`].map(...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good now?


// addCommas(9999999.9999) === "9,999,999.9999"
~~~
Loading