열정가득한 개발자의 이야기/Javascript Algorithm

3005. Count Elements With Maximum Frequency (javascript)

가문비나무 위의 독수리 2024. 9. 28. 15:27

 

Summarize : just counting the Maximun Frequency

 

so I use a Map to keep track of the counts

i store the elements in an Array as keys, and their counts as values.

Here is my code, and it feels too long, so I'm not satisfied with it.

so i ask to Gpt for refactoring.

and here is the answer.

 

the code by gpt looks better than mine...

and I learned something new, such as the nullish coalescing operator.

It returns the value on the right-hand side if the left-hand side is null or undefined