agent

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 takeDownCount
20 if (takeDownCount < 0) {
21 throw new Error('takeDownCount must be non-negative');
22 }
23
24 // Edge Case: initialBottlesCount out of range
25 if (initialBottlesCount < 0 || initialBottlesCount > 99) {
26 throw new Error('initialBottlesCount must be between 0 and 99');
27 }
28
29 // Edge Case: takeDownCount is 0
30 if (takeDownCount === 0) {
31 return [];
32 }
33
34 const verses = [];
35
36 for (let i = 0; i < takeDownCount; i++) {
37 const currentBottles = initialBottlesCount - i;
38
39 // Edge Case: currentBottles becomes negative
40 if (currentBottles < 0) {
41 break;
42 }
43
44 const nextBottles = currentBottles - 1;
45
46 // Generate the first line
47 let firstLine = '';
48 if (currentBottles === 0) {
49 firstLine = 'No more bottles of beer on the wall, no more bottles of beer.';
50 } else if (currentBottles === 1) {
51 firstLine = '1 bottle of beer on the wall, 1 bottle of beer.';
52 } else {
53 firstLine = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
54 }
55
56 // Generate the second line
57 let secondLine = '';
58 if (currentBottles === 0) {
59 secondLine = 'Go to the store and buy some more, 99 bottles of beer on the wall.';
60 } else if (currentBottles === 1) {
61 secondLine = 'Take it down and pass it around, no more bottles of beer on the wall.';
62 } else if (nextBottles === 1) {
63 secondLine = 'Take one down and pass it around, 1 bottle of beer on the wall.';
64 } else {
65 secondLine = `Take one down and pass it around, ${nextBottles} bottles of beer on the wall.`;
66 }
67
68 verses.push(firstLine);
69 verses.push(secondLine);
70
71 // Add empty string for spacing between verses, except for the last verse
72 if (i < takeDownCount - 1) {
73 verses.push('');
74 }
75 }
76
77 return verses;
1378};
79
80// Handled Edge Cases: Invalid input types, Negative takeDownCount, initialBottlesCount out of range, takeDownCount is 0, currentBottles becomes negative
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.