Drill

ProblemsTypeScript › warmup

Are these two an anagram

mediumwarmupTypeScript

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: string, other: string): boolean {
  
}

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 TypeScript
function isAnagram(text: string, other: string): boolean {
  const clean = (s: string) => s.toLowerCase().replace(/\s+/g, '').split('').sort().join('');
  return clean(text) === clean(other);
}

The same problem in another language

More warmup problems in TypeScript