One more question that I hear often is try to function with checks.
This strain is an anagram.
And actually, this stuff is super similar to a palindrome.
As you can see here, anagrams are words that have the same characters in the same quantity, which
actually means two strains and ingredients.
If we can rearrange strains and get the other.
And here are some examples of anagrams.
For example, listen and silent and so on.
So now let's throw the function is ending.
So here we have is anagram, and we know that we're getting here two strains that we want to compare.
So let's name it's three in one and stream two.
So what we want to check here is that this two strains have the same letters.
But in order to check this, we must just sort our strings.
In this case, we can simply compare the strains by equality.
But first of all, I would like to check here at length because if we have different lands in these
two strains, then it won't work.
This is why here, if the length of our first strain does not equal the length of our second strain,
then we just return false and we don't check anything.
And of course, here should be banned and not equal because we want to check that they are not equal.
The second thing that we want to do is convert it to lower case because actually we can have different
case, but the strains are still valid.
This is why, let's name it, a lower strain.
One.
And here with simpler called string one to lower case and we have to lowercase directly and javascript.
And here let's name lowest string two and we can worsts into two lowercase.
Now what we want to check, we want to check if this the strings are equal.
In this case, we must return false because they are not ending crumbs.
This is why here I will write.
If lowest in one equals lowest three in two, then this is false.
And this is not an anagram.
And the last one, we must write our logic.
And what I want to do, I want simpler to convert our strings to arrive in a certain way and merge it
directly back in string.
So for this, we can write, for example, sorted string one.
And here we will write lower string one dot split.
And here we want to split just by letters.
And here I am, just calling sort without any arguments.
So it will be sorted in some way.
And after this, we want to get a Strindberg.
This is by head join will get us back a string.
Now I want to do exactly the same on the second string.
And here now we can compare them because in this case, we sorted all our letters in the same direction.
And now here I can simply write return sorted string one equals sorted string two.
In this case, we're comparing two strings which were sorted, and we already know that it is an acronym.
If they are equal, let's check this out and jump into browser and where writing is, anagram.
And here we just provide in full and borrowing.
And as you can see, it is false because these are two different strings.
But let's now try was listen and silent, for example.
So here I am, right in lesson.
And on the right, I am right and silent.
And actually, where I get in here, true.
And it is working.
So what we are doing here, first of all, we are checking if length is the same word, come in here.
We have two strings lowercase.
So we're not here.
And now we're just sorting this two strings, which were converted to our arrays and then we're converting
them back to strings.
In this case, we're getting something like e-file and SD, but it is totally fine because we want to
just compare them.
And this is how your writing function to compare anagrams.