Check for an anagram
beginner Strings Challenge 2 of 18
Write isAnagram(a, b), which returns true when the two strings contain exactly the same letters and digits the same number of times.
Requirements
- Compare case-insensitively.
- Ignore spaces and punctuation, so
'Dormitory'and'dirty room!'are anagrams. - Letters must match in count as well as in kind.
- Return a boolean, never
undefined.
Expected output
isAnagram('listen', 'silent') → true isAnagram('Dormitory', 'dirty room!') → true isAnagram('aab', 'abb') → false
Test cases (6)
- ○simple anagram
- ○ignores case and spaces
- ○ignores punctuation
- ○same letters with different counts
- ○different lengths
- ○two empty strings are anagrams
solution.jsExecutes in your browser
Ctrl/⌘ + Enter to run tests · your code is saved in this browser
Results
Run the tests to see results here.