joseph

Finished
1//
2// This is only a SKELETON file for the 'Beer Song' exercise. It's been provided as a
3// convenience to get you started writing code faster.
4//
1/*
2 * Helper function to generate a single verse of the beer song
3 * @param {number} bottles - The number of bottles for this verse
4 * @return {string} - The complete verse
5 */
6const generateVerse = (bottles) => {
7 // Edge Case: When there are no bottles
8 if (bottles === 0) {
9 return [
10 'No more bottles of beer on the wall, no more bottles of beer.',
11 'Go to the store and buy some more, 99 bottles of beer on the wall.'
12 ];
13 }
14
15 // Edge Case: When there is only one bottle
16 if (bottles === 1) {
17 return [
18 '1 bottle of beer on the wall, 1 bottle of beer.',
19 'Take it down and pass it around, no more bottles of beer on the wall.'
20 ];
21 }
22
23 // Edge Case: When there are two bottles
24 if (bottles === 2) {
25 return [
26 '2 bottles of beer on the wall, 2 bottles of beer.',
27 'Take one down and pass it around, 1 bottle of beer on the wall.'
28 ];
29 }
30
31 // General case for more than two bottles
32 return [
33 `${bottles} bottles of beer on the wall, ${bottles} bottles of beer.`,
34 `Take one down and pass it around, ${bottles - 1} bottles of beer on the wall.`
35 ];
36};
537
638/**
739 * @param {number} initialBottlesCount
941 * @return {string[]}
1042 */
1143export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
44 // Edge Case: Invalid input values
45 if (initialBottlesCount < 0 || takeDownCount < 0) {
46 throw new Error('Bottle counts must be non-negative');
47 }
48
49 // Edge Case: When takeDownCount is 0
50 if (takeDownCount === 0) {
51 return [];
52 }
53
54 const result = [];
55
56 // Generate each verse in the requested range
57 for (let i = 0; i < takeDownCount; i++) {
58 const currentBottles = initialBottlesCount - i;
59
60 // Edge Case: If we go below 0 bottles, stop reciting
61 if (currentBottles < 0) {
62 break;
63 }
64
65 const verse = generateVerse(currentBottles);
66 result.push(...verse);
67
68 // Add an empty string for spacing between verses, except after the last verse
69 // Edge Case: Don't add spacing after the final verse
70 if (i < takeDownCount - 1) {
71 result.push('');
72 }
73 }
74
75 return result;
1376};
77
78// Handled Edge Cases:
79// 1. No bottles (0 bottles)
80// 2. One bottle (1 bottle)
81// 3. Two bottles (2 bottles)
82// 4. Invalid input values (negative numbers)
83// 5. Zero take down count
84// 6. Going below 0 bottles
85// 7. No spacing after the final verse
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.