armor

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 *
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 for the beer song
1012 */
1113export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
14 // Edge Case: Invalid input types
15 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
16 throw new Error('Both parameters must be numbers');
17 }
18
19 // Edge Case: Negative numbers
20 if (initialBottlesCount < 0 || takeDownCount < 0) {
21 throw new Error('Parameters must be non-negative');
22 }
23
24 // Edge Case: takeDownCount of 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: Going below 0 bottles
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 {
45 const currentBottleText = currentBottles === 1 ? '1 bottle' : `${currentBottles} bottles`;
46 const nextBottles = currentBottles - 1;
47 const nextBottleText = nextBottles === 0 ? 'no more bottles' :
48 nextBottles === 1 ? '1 bottle' :
49 `${nextBottles} bottles`;
50
51 const action = currentBottles === 1 ? 'Take it down and pass it around' :
52 'Take one down and pass it around';
53
54 verses.push(
55 `${currentBottleText} of beer on the wall, ${currentBottleText} of beer.`,
56 `${action}, ${nextBottleText} of beer on the wall.`
57 );
58 }
59
60 // Add empty string for spacing between verses, except for the last verse
61 if (i < takeDownCount - 1) {
62 verses.push('');
63 }
64 }
65
66 return verses;
1367};
68
69// Handled Edge Cases: Invalid input types, negative numbers, takeDownCount of 0, going below 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.