yahoo

Finished
1/* eslint-disable no-undef */
12//
23// This is only a SKELETON file for the 'Beer Song' exercise. It's been provided as a
34// convenience to get you started writing code faster.
45//
56
67/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
8 * Generates the lyrics for a range of verses in the 99 Bottles of Beer song.
9 *
10 * @param {number} initialBottlesCount - The starting number of bottles (0-99)
11 * @param {number} takeDownCount - The number of verses to generate (default: 1)
12 * @return {string[]} - Array of strings representing the lyrics
1013 */
1114export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
15 // Edge Case: Invalid input types
16 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
17 throw new Error('Both parameters must be numbers');
18 }
19
20 // Edge Case: Negative takeDownCount
21 if (takeDownCount < 0) {
22 throw new Error('takeDownCount must be non-negative');
23 }
24
25 // Edge Case: initialBottlesCount out of range
26 if (initialBottlesCount < 0 || initialBottlesCount > 99) {
27 throw new Error('initialBottlesCount must be between 0 and 99');
28 }
29
30 // Edge Case: takeDownCount is 0
31 if (takeDownCount === 0) {
32 return [];
33 }
34
35 const verses = [];
36
37 for (let i = 0; i < takeDownCount; i++) {
38 const currentBottles = initialBottlesCount - i;
39
40 // Edge Case: currentBottles becomes negative
41 if (currentBottles < 0) {
42 break;
43 }
44
45 verses.push(...generateVerse(currentBottles));
46
47 // Add empty string for spacing between verses, except for the last verse
48 if (i < takeDownCount - 1 && currentBottles > 0) {
49 verses.push('');
50 }
51 }
52
53 return verses;
1354};
55
56/**
57 * Generates a single verse of the 99 Bottles of Beer song.
58 *
59 * @param {number} numBottles - The number of bottles for this verse
60 * @return {string[]} - Array containing the two lines of the verse
61 */
62const generateVerse = (numBottles) => {
63 // Edge Case: Special case for 0 bottles
64 if (numBottles === 0) {
65 return [
66 'No more bottles of beer on the wall, no more bottles of beer.',
67 'Go to the store and buy some more, 99 bottles of beer on the wall.'
68 ];
69 }
70
71 // Edge Case: Special case for 1 bottle
72 if (numBottles === 1) {
73 return [
74 '1 bottle of beer on the wall, 1 bottle of beer.',
75 'Take it down and pass it around, no more bottles of beer on the wall.'
76 ];
77 }
78
79 // Edge Case: Special case for 2 bottles
80 if (numBottles === 2) {
81 return [
82 '2 bottles of beer on the wall, 2 bottles of beer.',
83 'Take one down and pass it around, 1 bottle of beer on the wall.'
84 ];
85 }
86
87 // General case for 3 or more bottles
88 return [
89 `${numBottles} bottles of beer on the wall, ${numBottles} bottles of beer.`,
90 `Take one down and pass it around, ${numBottles - 1} bottles of beer on the wall.`
91 ];
92};
93
94// Handled Edge Cases:
95// - Invalid input types
96// - Negative takeDownCount
97// - initialBottlesCount out of range (0-99)
98// - takeDownCount is 0
99// - currentBottles becomes negative
100// - Special case for 0 bottles
101// - Special case for 1 bottle
102// - Special case for 2 bottles
103// - General case for 3 or more 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.