This file contains 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
interface Without { | |
without(withoutWord: string): boolean; | |
} | |
// 1. Easiest / the way I'd do it | |
function youCantSpell(word: string): Without { | |
return { | |
without(withoutWord: string) { | |
return word.includes(withoutWord); | |
} | |
} | |
} | |
// 2. Using bind | |
function youCantSpell(word: string): Without { | |
return { | |
without: String.prototype.includes.bind(word) | |
} | |
} | |
// 3. Hot Shot Arrow function | |
const youCantSpell = (word: string): Without => ({ without: (withoutWord: string) => word.includes(withoutWord) }); | |
console.log(youCantSpell('awesome').without('wes')); // true | |
console.log(youCantSpell('functions').without('fun')); // true | |
console.log(youCantSpell('families').without('lies')); // true | |
console.log(youCantSpell('pneumonoultramicroscopicsilicovolcanoconiosis').without('volcano')); // true | |
console.log(youCantSpell('hottie').without('scottie')); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment