you can bite off ANYTHING you want. this language bites off "pizza".
TRANSLATED:
we could write a new bite function, just like last time.
function bitePizza(text) {
if (text.startsWith("pizza")) {
return "pizza"
}
throw new Error(`UNFORTUNATE error: expected 'pizza' but found '${text.slice(0, 5)}'!`)
}
ALTERNATIVELY, we could write a helper function that lets us bite off any string we want.
function biteString(string) {
return (text) => {
if (text.startsWith(string)) {
return string
}
throw new Error(`UNFORTUNATE error: expected '${string}' but found '${text.slice(0, string.length)}'!`)
}
}
now we can use it like this:
const bitePizza = biteString("pizza")
then this:
bitePizza(text)
back to the dream