Created
May 26, 2020 21:36
-
-
Save maccyber/c8b020fee1e2122db02882ed2f3e26ec to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const pluralize = (str, n) => str + (n !== 1 ? 's' : '') | |
const bottleText = n => `${n || 'No more'} ${pluralize('bottle', n)}` | |
function sing (start = 99, stop = 0) { | |
const [currentBottles, remainingBottles] = [bottleText(start), bottleText(start - 1)] | |
console.log(`${currentBottles} of beer on the wall, ${currentBottles.toLowerCase()} of beer.`) | |
if (!start) { | |
return console.log('Go to the store and buy some more, 99 bottles of beer on the wall') | |
} | |
console.log(`Take one down and pass it around, ${remainingBottles.toLowerCase()} of beer on the wall\n`) | |
if (start !== stop) { | |
sing(--start, stop) | |
} | |
} | |
module.exports = { | |
song: () => sing(), | |
verses: (start, stop) => sing(start, stop), | |
verse: verse => sing(verse, verse) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment