Determine if two strings are an anagram

Share this video with your friends

Send Tweet

The anagram test is commonly used to demonstrate how an naive implementation can perform significant order of magnitudes slower than an efficient one. We’ll also briefly go over why each implementation is not as efficient as you could make it.

A word is an anagram of another if you can rearrange its characters to produce the second word. Here we’ll write multiple increasingly more efficient functions that given two strings determines if they are anagrams of each other.

peterschussheim
peterschussheim
~ 8 years ago

This was an AWESOME video! Would love more of these showing similar utilities.

Basarat Ali Syed
Basarat Ali Syed(instructor)
~ 8 years ago

Thanks 🌹. Will do ❤️

Christian Pena Valerio
Christian Pena Valerio
~ 7 years ago

Awesome video. Shouldn't we compare the length of each word, and return false if lengths are not equal?

mrsoto
mrsoto
~ 7 years ago

String is iterable then you may apply for of without splitting it

mrsoto
mrsoto
~ 7 years ago

I prefer to use Array.from('string') to convert to an array and avoid N searchs

Yevgeniy
Yevgeniy
~ 7 years ago

modifying arguments is a bad practice

mac
mac
~ 7 years ago

Hi Basarat, great video! Could you please give examples on when is the best to use Map?

Chris Samuel
Chris Samuel
~ 7 years ago

I notice you used Map in this video to solve the problem but in TypeScript Map is not supported and it does not look like it is going to be supported anytime soon. What would be the best way to use this?

yiling
yiling
~ 7 years ago

It would be very helpful if you could publish a working demo into github.

I would be interested to see how you compiled the Map and Array.from into ES6 and made it work, because I am experiencing " TS2495: Type 'IterableIteratorShim<number>' is not an array type or a string type" errors after installing ES6-Shim and type definition files.

Luis  Avila
Luis Avila
~ 7 years ago

hi, great , but this msg in Ide Error:(48, 27) TS2304: Cannot find name 'Map'.

Gabriel
Gabriel
~ 7 years ago

No need for string.split('') for (let char of word) works fine.

great video!

infctr
infctr
~ 6 years ago
<deleted>