I have a very simple and silly test that is to compare two strings and check if it is an anagram.
I found this question, bt besides being old, it has no correct answer.
This using LINQ.
This not solve my question.
I managed to solve it using LINQ and also using a foreach, but the next challenge is to do it using sorting (without using LINQ). An anagram is a word or phrase formed by rearranging the letters of a different word or phrase. We can generalize this in string processing by saying that an anagram of a string is another string with exactly the same quantity of each character in it, in any order.
How can I sort without using LINQ?
private static bool CheckAnagramWithLinq(string texto1, string texto2)
{
return texto1.ToList().Intersect(texto2.ToList()).ToList().Count == texto1.Length;
}
private static bool CheckAnagramaWithoutLinq(string texto1, string texto2)
{
var charArray = texto1.ToCharArray();
foreach (var caracter in charArray)
{
if (texto2.Contains(caracter) && texto1.Count(x => x == caracter) == texto2.Count(x => x == caracter))
continue;
return false;
}
return true;
}