yahoo

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' for a range of verses.
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 strings representing the lyrics
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' || initialBottlesCount < 0 || initialBottlesCount > 99) {
16 throw new Error('initialBottlesCount must be between 0 and 99');
17 }
18
19 if (typeof takeDownCount !== 'number' || takeDownCount < 0) {
20 throw new Error('takeDownCount must be a non-negative number');
21 }
22
23 const verses = [];
24
25 // Edge Case: Handle when takeDownCount is 0 (no verses to recite)
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 when we go below 0 bottles
34 if (currentBottles < 0) {
35 break;
36 }
37
38 const nextBottles = currentBottles - 1;
39
40 // Generate the first line of the verse
41 let firstLine = '';
42 if (currentBottles === 0) {
43 firstLine = 'No more bottles of beer on the wall, no more bottles of beer.';
44 } else if (currentBottles === 1) {
45 firstLine = '1 bottle of beer on the wall, 1 bottle of beer.';
46 } else {
47 firstLine = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
48 }
49
50 // Generate the second line of the verse
51 let secondLine = '';
52 if (currentBottles === 0) {
53 secondLine = 'Go to the store and buy some more, 99 bottles of beer on the wall.';
54 } else if (nextBottles === 0) {
55 secondLine = 'Take it down and pass it around, no more bottles of beer on the wall.';
56 } else if (nextBottles === 1) {
57 secondLine = 'Take one down and pass it around, 1 bottle of beer on the wall.';
58 } else {
59 secondLine = `Take one down and pass it around, ${nextBottles} bottles of beer on the wall.`;
60 }
61
62 verses.push(firstLine);
63 verses.push(secondLine);
64
65 // Edge Case: Add empty string after each verse except the last one
66 if (i < takeDownCount - 1) {
67 verses.push('');
68 }
69
70 // Edge Case: Stop if we've reached the final verse (0 bottles)
71 if (currentBottles === 0) {
72 break;
73 }
74 }
75
76 return verses;
1377};
78
79// Handled Edge Cases:
80// 1. Invalid initialBottlesCount (not a number or out of range 0-99)
81// 2. Invalid takeDownCount (not a number or negative)
82// 3. takeDownCount is 0 (no verses to recite)
83// 4. Going below 0 bottles
84// 5. Special wording for 0 bottles
85// 6. Special wording for 1 bottle
86// 7. Special wording for taking the last bottle ("Take it down" vs "Take one down")
87// 8. Adding empty lines between verses
88// 9. Stopping after the final verse (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.