Finished
99 * @returns {string[]}
1010 */
1111 static verse(verseNumber) {
12 throw new Error('Remove this line and implement the function');
12 // Edge Case: Invalid verse number (less than 1 or greater than 12)
13 if (verseNumber < 1 || verseNumber > 12) {
14 throw new Error('Verse number must be between 1 and 12');
15 }
16
17 const characters = [
18 'the house that Jack built.',
19 'the malt',
20 'the rat',
21 'the cat',
22 'the dog',
23 'the cow with the crumpled horn',
24 'the maiden all forlorn',
25 'the man all tattered and torn',
26 'the priest all shaven and shorn',
27 'the rooster that crowed in the morn',
28 'the farmer sowing his corn',
29 'the horse and the hound and the horn'
30 ];
31
32 const verbs = [
33 '',
34 'lay in',
35 'ate',
36 'killed',
37 'worried',
38 'tossed',
39 'milked',
40 'kissed',
41 'married',
42 'woke',
43 'kept',
44 'belonged to'
45 ];
46
47 let result = ['This is ' + characters[verseNumber - 1]];
48
49 // Edge Case: First verse has no additional lines
50 if (verseNumber === 1) {
51 return result;
52 }
53
54 // Build the recursive structure
55 for (let i = verseNumber - 2; i >= 0; i--) {
56 if (i === 0) {
57 // Base case: connect to the house
58 result.push('that ' + verbs[i + 1] + ' ' + characters[i]);
59 } else {
60 // Regular case: connect to previous character
61 result.push('that ' + verbs[i + 1] + ' ' + characters[i]);
62 }
63 }
64
65 return result;
66 // Handled Edge Cases: Invalid verse number, first verse special case
1367 }
1468
1569 /**
1872 * @returns {string[]}
1973 */
2074 static verses(start, end) {
21 throw new Error('Remove this line and implement the function');
75 // Edge Case: Invalid range (start or end out of bounds, or start > end)
76 if (start < 1 || end > 12 || start > end) {
77 throw new Error('Invalid range: start must be between 1 and 12, end must be between 1 and 12, and start must not exceed end');
78 }
79
80 let result = [];
81 for (let i = start; i <= end; i++) {
82 const verseLines = this.verse(i);
83 result.push(...verseLines);
84 // Edge Case: Add empty line between verses (except after the last verse)
85 if (i < end) {
86 result.push('');
87 }
88 }
89
90 return result;
91 // Handled Edge Cases: Invalid range, proper spacing between verses
2292 }
2393}
Test NameStatus
verse one - the house that jack built
Pass
verse two - the malt that lay
Pass
verse three - the rat that ate
Pass
verse four - the cat that killed
Pass
verse five - the dog that worried
Pass
verse six - the cow with the crumpled horn
Pass
verse seven - the maiden all forlorn
Pass
verse eight - the man all tattered and torn
Pass
verse nine - the priest all shaven and shorn
Pass
verse ten - the rooster that crowed in the morn
Pass
verse eleven - the farmer sowing his corn
Pass
verse twelve - the horse and the hound and the horn
Pass
multiple verses
Pass
full rhyme
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.