Immune

Finished
44//
55
66/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
7 * Generates verses of the "99 Bottles of Beer" song.
8 *
9 * @param {number} initialBottlesCount - The starting number of bottles (0-99)
10 * @param {number} takeDownCount - How many verses to generate (default: 1)
11 * @return {string[]} - Array of verses
1012 */
1113export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
14 // Edge Case: Invalid input types
15 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
16 throw new Error('Both parameters must be numbers');
17 }
18
19 // Edge Case: Negative numbers
20 if (initialBottlesCount < 0 || takeDownCount < 0) {
21 throw new Error('Parameters must be non-negative');
22 }
23
24 // Edge Case: takeDownCount of 0
25 if (takeDownCount === 0) {
26 return [];
27 }
28
29 const verses = [];
30
31 for (let i = 0; i < takeDownCount; i++) {
32 const currentBottles = initialBottlesCount - i;
33
34 // Edge Case: Going below 0 bottles
35 if (currentBottles < 0) {
36 break;
37 }
38
39 if (currentBottles === 0) {
40 verses.push(
41 "No more bottles of beer on the wall, no more bottles of beer.",
42 "Go to the store and buy some more, 99 bottles of beer on the wall."
43 );
44 } else if (currentBottles === 1) {
45 verses.push(
46 "1 bottle of beer on the wall, 1 bottle of beer.",
47 "Take it down and pass it around, no more bottles of beer on the wall."
48 );
49 } else {
50 const nextBottles = currentBottles - 1;
51 const currentBottleText = `${currentBottles} bottles of beer`;
52 const nextBottleText = nextBottles === 1 ? "1 bottle of beer" :
53 nextBottles === 0 ? "no more bottles of beer" :
54 `${nextBottles} bottles of beer`;
55
56 verses.push(
57 `${currentBottleText} on the wall, ${currentBottleText}.`,
58 `Take one down and pass it around, ${nextBottleText} on the wall.`
59 );
60 }
61
62 // Add empty string for spacing between verses, except for the last verse
63 if (i < takeDownCount - 1) {
64 verses.push("");
65 }
66 }
67
68 return verses;
1369};
70
71// Handled Edge Cases: Invalid input types, negative numbers, takeDownCount of 0, going below 0 bottles
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.