Skip to content

Instantly share code, notes, and snippets.

@aderaaij
Last active November 13, 2017 14:11
Show Gist options
  • Save aderaaij/b166dc25834e7e123b92efd63b8687e5 to your computer and use it in GitHub Desktop.
Save aderaaij/b166dc25834e7e123b92efd63b8687e5 to your computer and use it in GitHub Desktop.
Examples of the `.startsWith()`, `.endsWith()`, `.includes()` and `.repeat()` es6 javascript methods.
const course = 'RFB2';
const flightNumber = '20-AC2018-jz';
const accountNumber = '825242631RT0001';
const make = 'BMW';
const model = 'x5';
const colour = 'Royal Blue';
// .startsWith(searchString [, position])
// https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
console.log(flightNumber.startsWith('AC', 3))
// .endsWith()
// .includes()
// .repeat()
function leftPad(str, length = 20) {
return `→ ${' '.repeat(length - str.length)}${str}`;
}
console.log(leftPad(make));
console.log(leftPad(model));
console.log(leftPad(colour));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment