Character Count Comparison
- JavaScript — AlgoExpert
Let’s keep this short and simple
This is AlgoExpert’s #24 “Generate Document”.
Our function will be passed two arguments.
They’re both strings and the first one is called “characters” and represents a characters available to us.
The second one (“document”) represents a string that we’re attempting to construct.
Our task is to determine whether or not we have enough of each letter in our first argument to successfully create our second argument.
Thinking it through
Simple enough, right?
- First, I want a frequency count of all letters in both arguments
- Then I’ll simply compare these counts to determine whether or not I can build out the document.
- If I can, I’ll return true and if not — false.
Full Solution
As mentioned above, what I’ve done is generated a tally of character frequencies in each argument and then compared them.
And that’s it!
Short and simple.