@ngel

Finished
44//
55
66/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
7 * Recites verses of the "99 Bottles of Beer" song.
8 *
9 * @param {number} initialBottlesCount - The starting number of bottles (0-99)
10 * @param {number} takeDownCount - The number of verses to recite (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: Handle invalid inputs
15 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
16 throw new Error('Both parameters must be numbers');
17 }
18
19 // Edge Case: Handle negative takeDownCount
20 if (takeDownCount < 0) {
21 throw new Error('takeDownCount must be non-negative');
22 }
23
24 // Edge Case: Handle when initialBottlesCount is out of range
25 if (initialBottlesCount < 0 || initialBottlesCount > 99) {
26 throw new Error('initialBottlesCount must be between 0 and 99');
27 }
28
29 const verses = [];
30
31 // Edge Case: Handle when takeDownCount is 0
32 if (takeDownCount === 0) {
33 return [];
34 }
35
36 for (let i = 0; i < takeDownCount; i++) {
37 const currentBottles = initialBottlesCount - i;
38
39 // Edge Case: Handle when we go below 0 bottles
40 if (currentBottles < 0) {
41 break;
42 }
43
44 let line1, line2;
45
46 if (currentBottles === 0) {
47 line1 = "No more bottles of beer on the wall, no more bottles of beer.";
48 line2 = "Go to the store and buy some more, 99 bottles of beer on the wall.";
49 } else if (currentBottles === 1) {
50 line1 = "1 bottle of beer on the wall, 1 bottle of beer.";
51 line2 = "Take it down and pass it around, no more bottles of beer on the wall.";
52 } else {
53 line1 = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
54 const nextBottles = currentBottles - 1;
55 if (nextBottles === 1) {
56 line2 = "Take one down and pass it around, 1 bottle 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 input types, negative takeDownCount, initialBottlesCount out of range, takeDownCount is 0, going below 0 bottles, special cases for 0, 1, and 2 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.