seahawk

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: Handle negative initial bottle counts
15 if (initialBottlesCount < 0) {
16 throw new Error('Initial bottle count cannot be negative');
17 }
18
19 // Edge Case: Handle negative take down counts
20 if (takeDownCount < 0) {
21 throw new Error('Take down count cannot be negative');
22 }
23
24 // Edge Case: Handle when takeDownCount is 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: Handle when currentBottles goes below 0
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 if (currentBottles === 2) {
50 verses.push(
51 '2 bottles of beer on the wall, 2 bottles of beer.',
52 'Take one down and pass it around, 1 bottle of beer on the wall.'
53 );
54 } else {
55 verses.push(
56 `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`,
57 `Take one down and pass it around, ${currentBottles - 1} bottles of beer on the wall.`
58 );
59 }
60
61 // Add empty string for spacing between verses, except after the last verse
62 if (i < takeDownCount - 1) {
63 verses.push('');
64 }
65 }
66
67 return verses;
1368};
69
70// Handled Edge Cases: negative initial bottle counts, negative take down counts, takeDownCount is 0, currentBottles going below 0
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.