DEV Community

Discussion on: 15 Killer 🗡 JS techniques you've probably never heard of 🔈🔥

Collapse
 
leocaprile profile image
Matías Fuentes

I' mean "killer techniques" naah, pretty basic stuff, good post for beginners, don't get me wrong. Also there's a better way to get the same result on the Occurrence Counting technique, check this:

const occurrences = ["a", "b", "c", "c", "d", "a", "a", "e", "f", "e", "f", "g", "f", "f", "f"];
const dict = {}

occurrences.forEach((letter)=>{
  if(dict[letter]){
    dict[letter]++
  } else {
    dict[letter] = 1
  }
})
Enter fullscreen mode Exit fullscreen mode

You make just one loop to get the occurrence counting, I think could be optimized more using maps.

Collapse
 
ironcladdev profile image
Conner Ow

I guess that make sense, some of these are more for beginners.

That does seem like a more efficient way to do it, thanks for the suggestion.