dada esta función
function isTastyCheese(cheeseName: string) { const TastyCheeses = ['camembert', 'maroilles'] if (TastyCheeses.includes(cheeseName)) { return 'yes so tasty' } return undefined }Me gustaría hacer algo como esto:
const answerCamembert = isTastyCheese('camembert') ? the_returned_value : 'no taste like sh*t' const answerCantal = isTastyCheese('cantal') ? the_returned_value : 'no taste like sh*t' console.log(answerCamembert) >>> 'yes so tasty' console.log(answerCantal) >>> 'no taste like sh*t'¿Cómo uso el operador ternario para hacer esto de manera concisa?
PD: Obviamente, la función presentada aquí es muy incorrecta, pero cambiarla no debería ser parte de la solución.