perfect

Finished
44//
55
66/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
7 * Generates the lyrics for a range of verses in 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 strings representing the song verses
1012 */
1113export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
14 // Edge Case: Validate input parameters are non-negative integers
15 if (!Number.isInteger(initialBottlesCount) || initialBottlesCount < 0 ||
16 !Number.isInteger(takeDownCount) || takeDownCount < 0) {
17 throw new Error('Both parameters must be non-negative integers');
18 }
19
20 // Edge Case: Handle when takeDownCount is 0 (no verses needed)
21 if (takeDownCount === 0) {
22 return [];
23 }
24
25 const verses = [];
26
27 for (let i = 0; i < takeDownCount; i++) {
28 const currentBottles = initialBottlesCount - i;
29
30 // Edge Case: Prevent negative bottle counts
31 if (currentBottles < 0) {
32 break;
33 }
34
35 verses.push(...generateVerse(currentBottles));
36
37 // Edge Case: Don't add empty line after the last verse in a sequence
38 if (i < takeDownCount - 1) {
39 verses.push('');
40 }
41 }
42
43 return verses;
44
45 // Handled Edge Cases: Invalid inputs, zero takeDownCount, negative bottle counts, trailing empty lines
1346};
47
48/**
49 * Generates a single verse of the 99 Bottles of Beer song.
50 *
51 * @param {number} numBottles - The number of bottles for this verse
52 * @return {string[]} - Array containing the two lines of the verse
53 */
54function generateVerse(numBottles) {
55 // Edge Case: Special handling for 0 bottles
56 if (numBottles === 0) {
57 return [
58 'No more bottles of beer on the wall, no more bottles of beer.',
59 'Go to the store and buy some more, 99 bottles of beer on the wall.'
60 ];
61 }
62
63 // Edge Case: Special handling for 1 bottle
64 if (numBottles === 1) {
65 return [
66 '1 bottle of beer on the wall, 1 bottle of beer.',
67 'Take it down and pass it around, no more bottles of beer on the wall.'
68 ];
69 }
70
71 // Edge Case: Special handling for 2 bottles
72 if (numBottles === 2) {
73 return [
74 '2 bottles of beer on the wall, 2 bottles of beer.',
75 'Take one down and pass it around, 1 bottle of beer on the wall.'
76 ];
77 }
78
79 // General case for 3 or more bottles
80 return [
81 `${numBottles} bottles of beer on the wall, ${numBottles} bottles of beer.`,
82 `Take one down and pass it around, ${numBottles - 1} bottles of beer on the wall.`
83 ];
84
85 // Handled Edge Cases: 0 bottles, 1 bottle, 2 bottles, 3+ bottles
86}
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.