1const getMaxLetter = (str) => {
2 let max = 0;
3 let maxChar = '';
4 str.split('').forEach((char) => {
5 if (str.split(char).length > max) {
6 max = str.split(char).length - 1;
7 maxChar = char;
8 }
9 });
10 return `The max letter is : ${maxChar} and the max number of times it is seen is: ${max} times`;
11};
1function maxChar(str) {
2 let charCountObj = {};
3 let maxChar = "";
4 let maxCount = 0;
5
6 // Fill out CharCountObj
7 // Updates new MaxCount
8
9 for (let i = 0; i < str.length; i++) {
10 const char = str[i];
11
12 charCountObj[char] = charCountObj[char] + 1 || 1;
13
14 if (charCountObj[char] > maxCount) {
15 maxChar = char;
16 maxCount = charCountObj[char];
17 }
18 }
19
20 return maxChar;
21}
22