Skip to content

Instantly share code, notes, and snippets.

@hperrin
Last active May 20, 2020 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hperrin/d86131552154ab0bb4ba2c85edad93d7 to your computer and use it in GitHub Desktop.
Save hperrin/d86131552154ab0bb4ba2c85edad93d7 to your computer and use it in GitHub Desktop.
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