Sha256: 8d739b501249a557838f6c54c97e37e689f2dcc8e1851085046f295c477a41d2
Contents?: true
Size: 1.08 KB
Versions: 185
Compression:
Stored size: 1.08 KB
Contents
function bottles(number) { if (number === 0) { return 'No more bottles'; } if (number === 1) { return '1 bottle'; } return `${number} bottles`; } function action(currentVerse) { if (currentVerse === 0) { return 'Go to the store and buy some more, '; } const sbj = currentVerse === 1 ? 'it' : 'one'; return `Take ${sbj} down and pass it around, `; } function nextBottle(currentVerse) { return `${bottles(nextVerse(currentVerse)).toLowerCase()} of beer on the wall.\n`; } function nextVerse(currentVerse) { return currentVerse === 0 ? 99 : currentVerse - 1; } class BeerSong { static verse(number) { const line1 = `${bottles(number)} of beer on the wall, `; const line2 = `${bottles(number).toLowerCase()} of beer.\n`; const line3 = action(number); const line4 = nextBottle(number); return [line1, line2, line3, line4].join(''); } static sing(first = 99, last = 0) { const verses = []; for (let i = first; i >= last; i--) { verses.push(this.verse(i)); } return verses.join('\n'); } } export default BeerSong;
Version data entries
185 entries across 185 versions & 1 rubygems