Finished
88 * @return {string}
99 */
1010export const translate = (text) => {
11 throw new Error('Remove this line and implement the function');
11 // Edge Case: Empty string input
12 if (!text || text.length === 0) {
13 return '';
14 }
15
16 // Split text into words
17 const words = text.split(' ');
18
19 // Process each word
20 const translatedWords = words.map(word => {
21 // Edge Case: Empty word (multiple spaces)
22 if (word.length === 0) {
23 return word;
24 }
25
26 // Edge Case: Word starts with vowel or special cases "xr" or "yt"
27 if (/^[aeiou]|^xr|^yt/.test(word)) {
28 return word + 'ay';
29 }
30
31 // Edge Case: Word starts with consonants followed by "qu"
32 const quMatch = word.match(/^([^aeiou]*qu)(.*)/);
33 if (quMatch) {
34 return quMatch[2] + quMatch[1] + 'ay';
35 }
36
37 // Edge Case: Word starts with consonants followed by "y"
38 const yMatch = word.match(/^([^aeiou]+)y(.*)/);
39 if (yMatch) {
40 return 'y' + yMatch[2] + yMatch[1] + 'ay';
41 }
42
43 // Edge Case: Word starts with consonants (general case)
44 const consonantMatch = word.match(/^([^aeiou]+)(.*)/);
45 if (consonantMatch) {
46 return consonantMatch[2] + consonantMatch[1] + 'ay';
47 }
48
49 // Edge Case: Fallback (should not happen with valid input)
50 return word + 'ay';
51 });
52
53 return translatedWords.join(' ');
1254};
55
56// Handled Edge Cases: Empty string input, Empty word (multiple spaces), Word starts with vowel or special cases "xr" or "yt", Word starts with consonants followed by "qu", Word starts with consonants followed by "y", Word starts with consonants (general case), Fallback case
Test NameStatus
word beginning with a
Pass
word beginning with e
Pass
word beginning with i
Pass
word beginning with o
Pass
word beginning with u
Pass
word beginning with a vowel and followed by a qu
Pass
word beginning with p
Pass
word beginning with k
Pass
word beginning with x
Pass
word beginning with q without a following u
Pass
word beginning with ch
Pass
word beginning with qu
Pass
word beginning with qu and a preceding consonant
Pass
word beginning with th
Pass
word beginning with thr
Pass
word beginning with sch
Pass
word beginning with yt
Pass
word beginning with xr
Pass
y is treated like a consonant at the beginning of a word
Pass
y is treated like a vowel at the end of a consonant cluster
Pass
y as second letter in two letter word
Pass
a whole phrase
Pass

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