Created
February 27, 2018 18:57
-
-
Save feload/7d2f428a214771635d40c100622ee6c9 to your computer and use it in GitHub Desktop.
String left pad.
This file contains hidden or 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
export const leftPad = (str, howMany, char = '0') => { | |
if(str.length >= howMany) return str; | |
const space = Array(howMany).fill(char); | |
const aStr = str.split(''); | |
const merge = space.concat(aStr); | |
merge.splice(0, aStr.length); | |
return merge.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment