How to Find What Character Appears Most in a String in JavaScript || Frequency Counter Technique

How to Find What Character Appears Most in a String in JavaScript || Frequency Counter Technique

DoableDanny

3 года назад

3,371 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Parvathi Sachin
Parvathi Sachin - 20.10.2022 23:57

I took one day to struggle with this concept....but after watching this video you made it so understandable and i got the concept and logic....this is just perfect!!!!!!!!!!!!

Ответить
Andres Ramirez
Andres Ramirez - 20.05.2021 19:50

You explained this so well, even i understood it

Ответить
Ganesh H
Ganesh H - 25.01.2021 11:20

Brilliant approach, never considered that object keys would be used this way. Also using || for the array initialization is also very clean. We could also put the max checking inside the loop to avoid another run through of the array like this:
let maxCount = 0
let maxChar = null
for(char of lcStr){
freqCounter[char] = freqCounter[char] + 1 || 1
if(freqCounter[char] > maxCount){
maxCount = freqCounter[char]
maxChar = char
}
}
Although it won't affect Big O regardless.

Ответить
Svejdam
Svejdam - 25.01.2021 00:08

From your channel will be a perfect free source mate. I also learn a lot from your videos. Keep rocking mate :)

Ответить