JSFiddle - React, Tailwind, and code Playground
by Peer Reynders
JavaScript
const topResult = (next) => (grade) =>
grade === 'A+' ? 'Nailed It! 🥳' : next(grade);
const midGrades = new Set(['A', 'B+', 'B', 'C']);
const midResult = (next) => (grade) =>
midGrades.has(grade) ? 'Passed 💃' : next(grade);
const lowResult = (next) => (grade) =>
grade === 'D' ? 'Barely Survived 😌' : next(grade);
const failResult = (_grade) => 'Failed 😢';
const studentFinalResult = topResult(midResult(lowResult(failResult)));
console.log(studentFinalResult('A+')); // "Nailed It! 🥳