Skip to content
Advertisement

Tag: count

Count frequency of different key values in Javascript object?

Looking for a very simple, elegant solution to count the frequency of different values in a javascript object. For example: I could probably loop over everything manually, but is there a simple and elegant solution, probably using reducers? Answer a reduce and a forEach. Object.entries to get the entries of each element of input array. Nullish coalescing operator(??) to shorten

Count matching letters once

I’m creating a kid’s learning tool that has a form which matches 4 letters to a word. I want to count the number of character matches in a word. But it counts duplicates of letters as 2 instead of 1. For example if the word is “loot”, and the user submits “flop”, the matching letters are 3 instead of 2,

Advertisement