Finished
44//
55
66export const parallelLetterFrequency = async (texts) => {
7 throw new Error('Remove this line and implement the function');
7 // Edge Case: Handle null or undefined input
8 if (texts === null || texts === undefined) {
9 return {};
10 }
11
12 // Edge Case: Handle empty array input
13 if (texts.length === 0) {
14 return {};
15 }
16
17 // Function to count letters in a single text
18 const countLetters = (text) => {
19 // Edge Case: Handle null or undefined text elements
20 if (text === null || text === undefined) {
21 return {};
22 }
23
24 const letterCount = {};
25 // Convert to lowercase and iterate through each character
26 for (const char of text.toLowerCase()) {
27 // Edge Case: Only count alphabetic characters (including Unicode)
28 // Use Unicode property escape to detect letters
29 if (/\p{L}/u.test(char)) {
30 letterCount[char] = (letterCount[char] || 0) + 1;
31 }
32 }
33 return letterCount;
34 };
35
36 // Process all texts in parallel
37 const results = await Promise.all(texts.map(countLetters));
38
39 // Combine all results into a single object
40 const totalCount = {};
41
42 // Edge Case: Handle empty results array
43 if (results.length === 0) {
44 return totalCount;
45 }
46
47 for (const result of results) {
48 for (const [letter, count] of Object.entries(result)) {
49 totalCount[letter] = (totalCount[letter] || 0) + count;
50 }
51 }
52
53 return totalCount;
854};
55
56// Handled Edge Cases: null/undefined input, empty array input, null/undefined text elements, non-alphabetic characters, empty results
Test NameStatus
no texts
Pass
one text with one letter
Pass
one text with multiple letters
Pass
two texts with one letter
Pass
two texts with multiple letters
Pass
ignore letter casing
Pass
ignore whitespace
Pass
ignore punctuation
Pass
ignore numbers
Pass
Unicode letters
Pass
combination of lower- and uppercase letters, punctuation and white space
Pass
large texts
Pass
many small texts
Pass

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