fistinz

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: Validate input parameters are non-negative integers
15 if (!Number.isInteger(initialBottlesCount) || initialBottlesCount < 0 ||
16 !Number.isInteger(takeDownCount) || takeDownCount < 0) {
17 throw new Error('Bottle counts 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 // Generate the specified number of verses
28 for (let i = 0; i < takeDownCount; i++) {
29 const currentBottles = initialBottlesCount - i;
30
31 // Edge Case: Prevent negative bottle counts
32 if (currentBottles < 0) {
33 break;
34 }
35
36 verses.push(...generateVerse(currentBottles));
37
38 // Edge Case: Don't add blank line after the last verse
39 if (i < takeDownCount - 1) {
40 verses.push('');
41 }
42 }
43
44 return verses;
45 // Handled Edge Cases: Invalid inputs, zero takeDownCount, negative bottle counts, last verse formatting
1346};
47
48/**
49 * Generates a single verse of the 99 Bottles of Beer song.
50 *
51 * @param {number} bottles - The number of bottles for this verse
52 * @return {string[]} - Array containing the two lines of the verse
53 */
54const generateVerse = (bottles) => {
55 // Edge Case: Special handling for 0 bottles
56 if (bottles === 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 (singular form)
64 if (bottles === 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 (transition from plural to singular)
72 if (bottles === 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 `${bottles} bottles of beer on the wall, ${bottles} bottles of beer.`,
82 `Take one down and pass it around, ${bottles - 1} bottles of beer on the wall.`
83 ];
84 // Handled Edge Cases: 0 bottles, 1 bottle, 2 bottles, general plural case
85};
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.