DEV Community

Discussion on: Anagrams Checker - Three JavaScript Solutions

Collapse
 
sem8 profile image
Sem Limi • Edited

Solution 1 might not be completely correct if you don't check that the length of s and t are the same otherwise return false like so:

 if (s.length !== t.length) {
    return false;
  }
Enter fullscreen mode Exit fullscreen mode

Otherwise this test will return true even though it should be false

console.log(anagrams("anagram", "nagarams")); // false
Enter fullscreen mode Exit fullscreen mode