Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f6b9aad

Browse files
upd: maxChars
1 parent 81ba695 commit f6b9aad

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

‎src/4_maxChars/index.ts‎

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,19 @@
77

88

99
// #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> = {};
2112

13+
for (let char of str) {
14+
charsObj[char] = charsObj[char] + 1 || 1;
15+
}
2216

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]);
3318

19+
return sortedEntries[sortedEntries.length - 1][0];
20+
}
3421

22+
// #2 Solution
3523
export const maxChar = (str: string): string => {
3624
const charsObj: Record<string, number> = {};
3725
let max: number = 0;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /