Created
May 15, 2020 02:35
-
-
Save sergiohidalgo/5f4a58dc096fe27cb4c6758b32f921f8 to your computer and use it in GitHub Desktop.
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
const exactLengthString = (input, length, filling) => { | |
let newString = ''; | |
for (var i = 1; i <= length / filling.length; i++) newString += filling; | |
newString += input.toString() | |
return newString.substring(newString.length - length, newString.length + length) | |
} | |
console.log(exactLengthString('100', 4, '0')) // 0100 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment