Lesson 46: My IsIsogram() Function solution

First, this was tough for me. I spent way to long looking for how to use the ranged for loops variables and how to add stuff to the std::map, but after a lot of searching online I think I have it. Here is the code.

bool FBullCowGame::IsIsogram(FString Word) const
{
	//treat 0 and 1 letter words as isograms
	if (Word.length() <= 1)	{ return true; }

	TMap<char, bool> LetterSeen; // setup our map

	for (auto Letter : Word) //for all letters of the word
	{
		Letter = tolower(Letter); // handles mixed case
			
		if (LetterSeen[Letter] == 1) //if the letter has been seen before, returns false
		{
			return false;
		}
		else // adds the letter to the TMAP LetterSeen
		{
			LetterSeen[Letter] = 1;
		}
	}
		
	return true;  // for example in cases where /0 is entered
}

Once I realized that the variable Letter was also the counter for the loop, I was able to use this with the map. The first mistake I did was a dumb one, I accidentally had the first if coded like this at first.
if Letter = (LetterSeen[Letter])
Obviously this didn’t work, and then I realized I had to use two equal signs, and ask if LetterSeen == 1 instead of what I was trying to do. After I cleared that up everything else fell into place.

Privacy & Terms