Finished
44//
55
66export const truncate = (input) => {
7 throw new Error('Remove this line and implement the function');
7 // Edge Case: null or undefined input
8 if (input === null || input === undefined) {
9 return '';
10 }
11
12 // Edge Case: empty string
13 if (input === '') {
14 return '';
15 }
16
17 // Convert to string if it's not already
18 const str = String(input);
19
20 // Edge Case: string with 5 or fewer characters
21 if (Array.from(str).length <= 5) {
22 return str;
23 }
24
25 // Edge Case: string with more than 5 Unicode characters
26 // Using Array.from to properly handle Unicode characters (including emojis)
27 const characters = Array.from(str);
28 return characters.slice(0, 5).join('');
829};
30
31// Handled Edge Cases: null or undefined input, empty string, string with 5 or fewer characters, string with more than 5 Unicode characters
Test NameStatus
English language short
Pass
English language long
Pass
German language short (broth)
Pass
German language long (bear carpet → beards)
Pass
Bulgarian language short (good)
Pass
Greek language short (health)
Pass
Maths short
Pass
Maths long
Pass
English and emoji short
Pass
Emoji short
Pass
Emoji long
Pass
Royal Flush?
Pass

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