sn62

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 - The number of 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: Handle negative initial bottles count
15 if (initialBottlesCount < 0) {
16 initialBottlesCount = 0;
17 }
18
19 // Edge Case: Handle initial bottles count greater than 99
20 if (initialBottlesCount > 99) {
21 initialBottlesCount = 99;
22 }
23
24 // Edge Case: Handle negative take down count
25 if (takeDownCount < 0) {
26 takeDownCount = 0;
27 }
28
29 const verses = [];
30
31 for (let i = 0; i < takeDownCount; i++) {
32 const currentBottles = initialBottlesCount - i;
33
34 // Edge Case: Prevent going below 0 bottles
35 if (currentBottles < 0) {
36 break;
37 }
38
39 verses.push(...generateVerse(currentBottles));
40
41 // Edge Case: Don't add empty line after the last verse
42 if (i < takeDownCount - 1) {
43 verses.push('');
44 }
45 }
46
47 return verses;
1348};
49
50/**
51 * Generates a single verse of the 99 Bottles of Beer song.
52 *
53 * @param {number} bottles - The number of bottles for this verse
54 * @return {string[]} - Array containing the lines of the verse
55 */
56const generateVerse = (bottles) => {
57 // Edge Case: Handle 0 bottles (special case)
58 if (bottles === 0) {
59 return [
60 'No more bottles of beer on the wall, no more bottles of beer.',
61 'Go to the store and buy some more, 99 bottles of beer on the wall.'
62 ];
63 }
64
65 // Edge Case: Handle 1 bottle (singular form)
66 if (bottles === 1) {
67 return [
68 '1 bottle of beer on the wall, 1 bottle of beer.',
69 'Take it down and pass it around, no more bottles of beer on the wall.'
70 ];
71 }
72
73 // Edge Case: Handle 2 bottles (transition from plural to singular)
74 if (bottles === 2) {
75 return [
76 '2 bottles of beer on the wall, 2 bottles of beer.',
77 'Take one down and pass it around, 1 bottle of beer on the wall.'
78 ];
79 }
80
81 // General case for 3 or more bottles
82 return [
83 `${bottles} bottles of beer on the wall, ${bottles} bottles of beer.`,
84 `Take one down and pass it around, ${bottles - 1} bottles of beer on the wall.`
85 ];
86};
87
88// Handled Edge Cases:
89// - Negative initial bottles count
90// - Initial bottles count greater than 99
91// - Negative take down count
92// - Going below 0 bottles during iteration
93// - Adding empty line after each verse except the last
94// - Special wording for 0 bottles
95// - Special wording for 1 bottle
96// - Special wording for 2 bottles (transition to singular)
97// - General case for 3+ 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.