You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The IsAnagram function is not checking per-element counts. It is only checking if they have the same elements, but not if the count of each element matches.
A more appropriate name for the current logic is something like ContainsNoDifferingElements or IntersectsMatch rather than IsAnagram. I would recommend changing the name or the logic of the method.
Note: If you aren't going to check per-element counts, then you should also get rid of this check in IsAnagrams:
if(source.Length!=other.Length)returnfalse;
because length doesn't matter if you don't also check per-element counts.
To Reproduce
Add the following case to the IsAnagram unit tests:
Describe the bug
The
IsAnagram
function is not checking per-element counts. It is only checking if they have the same elements, but not if the count of each element matches.A more appropriate name for the current logic is something like
ContainsNoDifferingElements
orIntersectsMatch
rather thanIsAnagram
. I would recommend changing the name or the logic of the method.To Reproduce
Add the following case to the
IsAnagram
unit tests:Expected behavior
Spans of the same length and elements but different per-element counts should not be considered re-orders/anagrams of each other.
Environment:
master branch
Additional context
I have written my own version of this algorithm in C# (that fixes this issue) if interested here...
The text was updated successfully, but these errors were encountered: