future

Finished
44//
55
66/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
7 * Generates the lyrics for the beer song starting from a given number of bottles
8 * @param {number} initialBottlesCount - The initial number of bottles (0-99)
9 * @param {number} takeDownCount - How many verses to generate (default: 1)
10 * @return {string[]} - Array of verses for the beer song
1011 */
1112export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
13 // Edge Case: Handle invalid inputs
14 if (typeof initialBottlesCount !== 'number' || initialBottlesCount < 0 || initialBottlesCount > 99) {
15 throw new Error('Initial bottles count must be between 0 and 99');
16 }
17
18 if (typeof takeDownCount !== 'number' || takeDownCount < 0) {
19 throw new Error('Take down count must be a non-negative number');
20 }
21
22 const verses = [];
23
24 // Edge Case: Handle when takeDownCount is 0
25 if (takeDownCount === 0) {
26 return [];
27 }
28
29 for (let i = 0; i < takeDownCount; i++) {
30 const currentBottles = initialBottlesCount - i;
31
32 // Edge Case: Handle negative bottle counts
33 if (currentBottles < 0) {
34 break;
35 }
36
37 if (currentBottles === 0) {
38 verses.push(
39 'No more bottles of beer on the wall, no more bottles of beer.',
40 'Go to the store and buy some more, 99 bottles of beer on the wall.'
41 );
42 } else if (currentBottles === 1) {
43 verses.push(
44 '1 bottle of beer on the wall, 1 bottle of beer.',
45 'Take it down and pass it around, no more bottles of beer on the wall.'
46 );
47 } else if (currentBottles === 2) {
48 verses.push(
49 '2 bottles of beer on the wall, 2 bottles of beer.',
50 'Take one down and pass it around, 1 bottle of beer on the wall.'
51 );
52 } else {
53 verses.push(
54 `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`,
55 `Take one down and pass it around, ${currentBottles - 1} bottles of beer on the wall.`
56 );
57 }
58
59 // Edge Case: Add empty string after each verse except the last one
60 if (i < takeDownCount - 1) {
61 verses.push('');
62 }
63 }
64
65 return verses;
1366};
67
68// Handled Edge Cases: invalid inputs, takeDownCount is 0, negative bottle counts, 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.