Skip to content

Instantly share code, notes, and snippets.

@feload
Created February 27, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feload/7d2f428a214771635d40c100622ee6c9 to your computer and use it in GitHub Desktop.
Save feload/7d2f428a214771635d40c100622ee6c9 to your computer and use it in GitHub Desktop.
String left pad.
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