Created
January 12, 2021 05:20
-
-
Save milleraundra/6e1a4847eb8d8b8d97e08b7832b742eb to your computer and use it in GitHub Desktop.
Last Christmas by WHAM! as a recursive function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ChristmasThisYear(new Lover(), new Heart()); | |
function ChristmasThisYear(baby, heart) { | |
baby.give(heart) | |
.catch((veryNextDay) => { | |
if (veryNextDay === 'Gave it away') { | |
let someoneSpecial = new Lover(); | |
return ChristmasThisYear(someoneSpecial, heart); | |
// return tears | |
} | |
}); | |
} | |
class Heart { | |
giveAway() { | |
return 'Gave it away' | |
}; | |
} | |
class Lover { | |
give(heart) { | |
return new Promise((resolve, reject) => { | |
reject(heart.giveAway()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment