Drill

ProblemsJavaScript › warmup

Are these two an anagram

mediumwarmupJavaScript

A word game checks whether one phrase uses exactly the same letters as another.

isAnagram(text: string, other: string) → bool

Solve it in the editor →

Where you start

function isAnagram(text, other) {
  
}

Worked examples

CallResult
isAnagram("Listen", "Silent")true
isAnagram("a b", "ba")true
isAnagram("hello", "world")false
isAnagram("abc", "ab")false

Hint

Strip and lowercase both, then compare the sorted characters, or count them.

Reference solution in JavaScript
function isAnagram(text, other) {
  const clean = (s) => s.toLowerCase().replace(/\s+/g, '').split('').sort().join('');
  return clean(text) === clean(other);
}

The same problem in another language

More warmup problems in JavaScript