unicode

Finished
44//
55
66/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
7 * Recites the lyrics to '99 Bottles of Beer on the Wall'
8 * @param {number} initialBottlesCount - The starting number of bottles (0-99)
9 * @param {number} takeDownCount - How many verses to recite (default: 1)
10 * @return {string[]} - Array of lyrics lines
1011 */
1112export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
13 // Edge Case: Invalid input types
14 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
15 throw new Error('Both parameters must be numbers');
16 }
17
18 // Edge Case: Negative numbers
19 if (initialBottlesCount < 0 || takeDownCount < 0) {
20 throw new Error('Bottle counts cannot be negative');
21 }
22
23 // Edge Case: takeDownCount of 0
24 if (takeDownCount === 0) {
25 return [];
26 }
27
28 const result = [];
29
30 for (let i = 0; i < takeDownCount; i++) {
31 const currentBottles = initialBottlesCount - i;
32
33 // Edge Case: Going below 0 bottles
34 if (currentBottles < 0) {
35 break;
36 }
37
38 const nextBottles = currentBottles - 1;
39
40 // Generate the first line
41 const firstLine = `${bottleText(currentBottles)} of beer on the wall, ${bottleText(currentBottles).toLowerCase()} of beer.`;
42 result.push(firstLine);
43
44 // Generate the second line based on the number of bottles
45 let secondLine;
46 if (currentBottles > 1) {
47 secondLine = `Take one down and pass it around, ${bottleText(nextBottles).toLowerCase()} of beer on the wall.`;
48 } else if (currentBottles === 1) {
49 secondLine = `Take it down and pass it around, ${bottleText(nextBottles).toLowerCase()} of beer on the wall.`;
50 } else { // currentBottles === 0
51 secondLine = 'Go to the store and buy some more, 99 bottles of beer on the wall.';
52 }
53
54 result.push(secondLine);
55
56 // Add empty line between verses except for the last verse
57 if (i < takeDownCount - 1) {
58 result.push('');
59 }
60 }
61
62 return result;
1363};
64
65/**
66 * Helper function to generate the correct bottle text
67 * @param {number} count - Number of bottles
68 * @return {string} - Correctly formatted bottle text
69 */
70const bottleText = (count) => {
71 // Edge Case: Special text for 0 bottles
72 if (count === 0) {
73 return 'No more bottles';
74 }
75
76 // Edge Case: Special text for 1 bottle
77 if (count === 1) {
78 return '1 bottle';
79 }
80
81 // Edge Case: Plural form for 2 or more bottles
82 return `${count} bottles`;
83};
84
85// Handled Edge Cases: Invalid input types, negative numbers, takeDownCount of 0, going below 0 bottles, special text for 0 bottles, special text for 1 bottle, plural form for 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.