Skip to content

Instantly share code, notes, and snippets.

@sergiohidalgo
Created May 15, 2020 02:35
Show Gist options
  • Save sergiohidalgo/5f4a58dc096fe27cb4c6758b32f921f8 to your computer and use it in GitHub Desktop.
Save sergiohidalgo/5f4a58dc096fe27cb4c6758b32f921f8 to your computer and use it in GitHub Desktop.
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