Last active
November 13, 2017 14:11
-
-
Save aderaaij/b166dc25834e7e123b92efd63b8687e5 to your computer and use it in GitHub Desktop.
Examples of the `.startsWith()`, `.endsWith()`, `.includes()` and `.repeat()` es6 javascript methods.
This file contains hidden or 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 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