Created
February 26, 2017 21:20
-
-
Save dmi3y/59c0ecd4023d37a2d904854ebefc6f7f to your computer and use it in GitHub Desktop.
Number padder
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
function padding(num, sep) { | |
var numarr = num['toString']().split('') | |
var numarrLen = numarr.length | |
var out = [] | |
for (;numarrLen--;) { | |
var num = numarr[numarrLen] | |
out.unshift(num) | |
if (numarr.length !== numarrLen && num % 3 === 0) out.unshift(sep) | |
} | |
return out.join('') | |
} |
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
function padding(num, sep) { | |
var numarr = num['toString']().split('').reverse() | |
var haho = numarr.reduce((acc, el, ix) => acc.concat([ix&&!(ix % 3) ? sep : "", el]), []) | |
return haho.filter(el => !!el).reverse().join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment