Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const splitWith3 = val => {
- return val
- .split(/(\d{3})/g)
- .filter(Boolean)
- }
- const split = num => {
- switch (num.length % 3) {
- case 2:
- return [
- num.substr(0, 2),
- ...splitWith3(num.replace(/^\d{2}/, ''))
- ]
- break
- case 1:
- return [
- num.substr(0, 1),
- ...splitWith3(num.replace(/^\d{1}/, ''))
- ]
- break
- case 0:
- return splitWith3(num)
- break
- }
- }
- export default split
Add Comment
Please, Sign In to add comment