Konoha

Finished
44//
55
66/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
7 * Generates the lyrics for the beer song starting from a given number of bottles.
8 *
9 * @param {number} initialBottlesCount - The initial number of bottles (0-99)
10 * @param {number} takeDownCount - How many verses to generate (default: 1)
11 * @return {string[]} - Array of verses for the beer song
1012 */
1113export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
14 // Edge Case: Handle invalid inputs
15 if (initialBottlesCount < 0 || initialBottlesCount > 99) {
16 throw new Error('Initial bottles count must be between 0 and 99');
17 }
18
19 if (takeDownCount < 0) {
20 throw new Error('Take down count must be non-negative');
21 }
22
23 const verses = [];
24
25 // Edge Case: Handle when takeDownCount is 0
26 if (takeDownCount === 0) {
27 return [];
28 }
29
30 for (let i = 0; i < takeDownCount; i++) {
31 const currentBottles = initialBottlesCount - i;
32
33 // Edge Case: Handle negative bottle counts
34 if (currentBottles < 0) {
35 break;
36 }
37
38 let line1, line2;
39
40 if (currentBottles === 0) {
41 // Special case for 0 bottles
42 line1 = "No more bottles of beer on the wall, no more bottles of beer.";
43 line2 = "Go to the store and buy some more, 99 bottles of beer on the wall.";
44 } else if (currentBottles === 1) {
45 // Special case for 1 bottle
46 line1 = "1 bottle of beer on the wall, 1 bottle of beer.";
47 line2 = "Take it down and pass it around, no more bottles of beer on the wall.";
48 } else {
49 // General case for 2 or more bottles
50 line1 = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
51
52 const nextBottles = currentBottles - 1;
53 if (nextBottles === 1) {
54 line2 = `Take one down and pass it around, 1 bottle of beer on the wall.`;
55 } else if (nextBottles === 0) {
56 line2 = "Take one down and pass it around, no more bottles of beer on the wall.";
57 } else {
58 line2 = `Take one down and pass it around, ${nextBottles} bottles of beer on the wall.`;
59 }
60 }
61
62 verses.push(line1);
63 verses.push(line2);
64
65 // Edge Case: Don't add empty line after the last verse
66 if (i < takeDownCount - 1) {
67 verses.push("");
68 }
69 }
70
71 return verses;
1372};
73
74// Handled Edge Cases: Invalid inputs (negative or out of range values), takeDownCount of 0, negative bottle counts, special cases for 0 and 1 bottles, proper pluralization
Test NameStatus
first generic verse
Pass
last generic verse
Pass
verse with 2 bottles
Pass
verse with 1 bottle
Pass
verse with 0 bottles
Pass
first two verses
Pass
last three verses
Pass
all verses
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.