Finished
88 * @returns {Promise<Object.<string, number>>}
99 */
1010export const parallelLetterFrequency = async (texts) => {
11 throw new Error('Remove this line and implement the function');
11 // Edge Case: Handle null or undefined input
12 if (texts === null || texts === undefined) {
13 return {};
14 }
15
16 // Edge Case: Handle empty array input
17 if (texts.length === 0) {
18 return {};
19 }
20
21 // Create an array of promises for counting letters in each text
22 const promises = texts.map(text => {
23 return new Promise((resolve) => {
24 // Edge Case: Handle null or undefined text elements
25 if (text === null || text === undefined) {
26 resolve({});
27 return;
28 }
29
30 const letterCount = {};
31 // Convert to lowercase and process each character
32 for (const char of text.toLowerCase()) {
33 // Edge Case: Only count alphabetic characters
34 if (char >= 'a' && char <= 'z') {
35 letterCount[char] = (letterCount[char] || 0) + 1;
36 }
37 }
38 resolve(letterCount);
39 });
40 });
41
42 // Wait for all promises to complete
43 const results = await Promise.all(promises);
44
45 // Combine all results into a single frequency object
46 const finalCount = {};
47
48 // Edge Case: Handle empty results array
49 if (results.length === 0) {
50 return finalCount;
51 }
52
53 for (const result of results) {
54 for (const [letter, count] of Object.entries(result)) {
55 finalCount[letter] = (finalCount[letter] || 0) + count;
56 }
57 }
58
59 return finalCount;
1260};
61
62// Handled Edge Cases: null/undefined input, empty array, 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.