Skip to content

Instantly share code, notes, and snippets.

@maccyber
Created May 26, 2020 21:36
Show Gist options
  • Save maccyber/c8b020fee1e2122db02882ed2f3e26ec to your computer and use it in GitHub Desktop.
Save maccyber/c8b020fee1e2122db02882ed2f3e26ec to your computer and use it in GitHub Desktop.
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