|
7 | 7 |
|
8 | 8 |
|
9 | 9 | // #1 Solution
|
10 | | -// export const maxChar = (str: string): string => { |
11 | | -// const charsObj: Record<string, number> = {}; |
12 | | - |
13 | | -// for (let char of str) { |
14 | | -// charsObj[char] = charsObj[char] + 1 || 1; |
15 | | -// } |
16 | | - |
17 | | -// const sortedEntries = Object.entries(charsObj).sort((a, b) => a[1] - b[1]); |
18 | | - |
19 | | -// return sortedEntries[sortedEntries.length - 1][0]; |
20 | | -// } |
| 10 | +export const maxChar = (str: string): string => { |
| 11 | + const charsObj: Record<string, number> = {}; |
21 | 12 |
|
| 13 | + for (let char of str) { |
| 14 | + charsObj[char] = charsObj[char] + 1 || 1; |
| 15 | + } |
22 | 16 |
|
23 | | -// max = 0; |
24 | | -/* |
25 | | - 'hello' |
26 | | - { |
27 | | - h: 1, |
28 | | - e: 1, |
29 | | - l: 2, |
30 | | - o: 1, |
31 | | - } |
32 | | -*/ |
| 17 | + const sortedEntries = Object.entries(charsObj).sort((a, b) => a[1] - b[1]); |
33 | 18 |
|
| 19 | + return sortedEntries[sortedEntries.length - 1][0]; |
| 20 | +} |
34 | 21 |
|
| 22 | +// #2 Solution |
35 | 23 | export const maxChar = (str: string): string => {
|
36 | 24 | const charsObj: Record<string, number> = {};
|
37 | 25 | let max: number = 0;
|
|
0 commit comments