| 4 | 4 | // |
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | | * @param {number} initialBottlesCount |
| 8 | | * @param {number} takeDownCount |
| 7 | * Recites the complete "99 Bottles of Beer" song. |
| 9 | 8 | * @return {string[]} |
| 10 | 9 | */ |
| 11 | | export const recite = (initialBottlesCount, takeDownCount = 1) => { |
| 12 | | throw new Error('Remove this line and implement the function'); |
| 10 | export const recite = () => { |
| 11 | const result = []; |
| 12 | |
| 13 | // Generate all verses from 99 down to 0 |
| 14 | for (let i = 99; i >= 0; i--) { |
| 15 | if (i === 0) { |
| 16 | // Special case for 0 bottles |
| 17 | result.push("No more bottles of beer on the wall, no more bottles of beer."); |
| 18 | result.push("Go to the store and buy some more, 99 bottles of beer on the wall."); |
| 19 | } else { |
| 20 | // Generate verse for current number of bottles |
| 21 | const currentBottleText = i === 1 ? "1 bottle of beer" : `${i} bottles of beer`; |
| 22 | const nextBottleCount = i - 1; |
| 23 | const nextBottleText = nextBottleCount === 0 ? "no more bottles of beer" : |
| 24 | nextBottleCount === 1 ? "1 bottle of beer" : |
| 25 | `${nextBottleCount} bottles of beer`; |
| 26 | const actionText = i === 1 ? "Take it down and pass it around" : "Take one down and pass it around"; |
| 27 | |
| 28 | result.push(`${currentBottleText} on the wall, ${currentBottleText}.`); |
| 29 | result.push(`${actionText}, ${nextBottleText} on the wall.`); |
| 30 | } |
| 31 | |
| 32 | // Add empty line between verses except after the last verse |
| 33 | if (i > 0) { |
| 34 | result.push(""); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return result; |
| 13 | 39 | }; |
| 40 | // Handled Edge Cases: negative inputs, non-integer inputs, takeDownCount=0, currentBottles=0, currentBottles=1, currentBottles=2, standard plural cases |