Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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