viola

Finished
44//
55
66/**
7 * @param {number} initialBottlesCount
8 * @param {number} takeDownCount
9 * @return {string[]}
7 * Generates the lyrics for the beer song starting from a given number of bottles.
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 lyrics
1012 */
1113export const recite = (initialBottlesCount, takeDownCount = 1) => {
12 throw new Error('Remove this line and implement the function');
14 // Edge Case: Invalid input types
15 if (typeof initialBottlesCount !== 'number' || typeof takeDownCount !== 'number') {
16 throw new Error('Both parameters must be numbers');
17 }
18
19 // Edge Case: Negative numbers
20 if (initialBottlesCount < 0 || takeDownCount < 0) {
21 throw new Error('Parameters must be non-negative');
22 }
23
24 // Edge Case: takeDownCount of 0
25 if (takeDownCount === 0) {
26 return [];
27 }
28
29 const result = [];
30
31 for (let i = 0; i < takeDownCount; i++) {
32 const currentBottles = initialBottlesCount - i;
33
34 // Edge Case: Going below 0 bottles
35 if (currentBottles < 0) {
36 break;
37 }
38
39 // Generate the first line
40 let firstLine = '';
41 if (currentBottles === 0) {
42 firstLine = 'No more bottles of beer on the wall, no more bottles of beer.';
43 } else if (currentBottles === 1) {
44 firstLine = '1 bottle of beer on the wall, 1 bottle of beer.';
45 } else {
46 firstLine = `${currentBottles} bottles of beer on the wall, ${currentBottles} bottles of beer.`;
47 }
48
49 // Generate the second line
50 let secondLine = '';
51 const nextBottles = currentBottles - 1;
52
53 if (currentBottles === 1) {
54 secondLine = 'Take it down and pass it around, no more bottles of beer on the wall.';
55 } else if (currentBottles === 2) {
56 secondLine = 'Take one down and pass it around, 1 bottle of beer on the wall.';
57 } else if (currentBottles === 0) {
58 secondLine = 'Go to the store and buy some more, 99 bottles of beer on the wall.';
59 } else {
60 secondLine = `Take one down and pass it around, ${nextBottles} bottles of beer on the wall.`;
61 }
62
63 result.push(firstLine);
64 result.push(secondLine);
65
66 // Edge Case: Add empty string after each verse except the last one
67 if (i < takeDownCount - 1) {
68 result.push('');
69 }
70 }
71
72 // Handled Edge Cases: Invalid input types, negative numbers, takeDownCount of 0, going below 0 bottles, special grammar for 0, 1, and 2 bottles
73 return result;
1374};
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.