When in doubt — use functions.
const topResult = (next) => (grade) => grade === 'A+' ? 'Nailed It! 🥳' : next(grade); const midGrades = new Set(['A', 'B+', 'B']); const midResult = (next) => (grade) => midGrades.has(grade) ? 'Passed 💃' : next(grade); const lowResult = (next) => (grade) => grade === 'C' ? 'Barely Survived 😌' : next(grade); const failResult = (_grade) => 'Failed 😢'; const studentFinalResult = topResult(midResult(lowResult(failResult))); console.log(studentFinalResult('A+')); // "Nailed It! 🥳
😁
MDN: Closures
This is uniquely terrible. It's so much less readable than either an if/else or a switch.
This is uniquely terrible.
Chain of Responsibility sends its regards.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
When in doubt — use functions.
😁
MDN: Closures
This is uniquely terrible. It's so much less readable than either an if/else or a switch.
Chain of Responsibility sends its regards.