Skip to content

Instantly share code, notes, and snippets.

@colorful-tones
Last active September 24, 2018 20:40
Show Gist options
  • Save colorful-tones/8356f9f82538501c948938b3a0ad1fed to your computer and use it in GitHub Desktop.
Save colorful-tones/8356f9f82538501c948938b3a0ad1fed to your computer and use it in GitHub Desktop.
[Left pad] simple left page function from Wes Bos's ES6 course #JavaScript #utility
// https://courses.wesbos.com/account/access/5b6921eb99ce1f5578c26a50/view/174357553
function left_pad( str, length = 20 ) {
return `-> ${' '.repeat( length - str.length )}${str};
}
console.log( left_pad( 'All' );
console.log( left_pad( 'these' );
console.log( left_pad( 'strings' );
console.log( left_pad( 'should' );
console.log( left_pad( 'be' );
console.log( left_pad( 'right' );
console.log( left_pad( 'justified' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment