Last active
May 20, 2020 05:22
-
-
Save hperrin/d86131552154ab0bb4ba2c85edad93d7 to your computer and use it in GitHub Desktop.
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
function verses(bottles) { | |
const count = (b, cap) => `${b || `${cap ? 'N' : 'n'}o more`} bottle${b == 1 ? '' : 's'}`; | |
return [...new Array(bottles + 1)].map((v, i) => bottles - i).map(b => [ | |
`${count(b, true)} of beer on the wall, ${count(b)} of beer.`, | |
b > 0 | |
? `Take one down and pass it around, ${count(b - 1)} of beer on the wall.` | |
: `Go to the store and buy some more, ${count(bottles)} of beer on the wall.` | |
]); | |
} | |
const container = document.createElement('pre'); | |
container.innerText = verses(99).map(verse => verse.join('\n')).join('\n\n'); | |
document.body.appendChild(container); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment