Here's my IsIsogram(), heavily commented

It’s probably pretty similar to what you other guys have, but I tried to comment it heavily if somebody have some questions about it.

bool FBullCowGame::IsIsogram(FString Word) const
{
    // treat 0 and 1 letter words as isogram
    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);		// handle mixed case
	    if (LetterSeen[Letter])			// Have we seen the letter before? A map is initally populated with bool = false for values that haven't been specified
	    {								// Yes, we have, so...
		    return false;				// ...let's return false to state that it isn't an isogram
	    }
	    else {							// No, we haven't, so...
		    LetterSeen[Letter] = true;	// ...let's make a note of the letter we are checking in the map by setting its value to true
	    }
    }

return true;							// Yes, the word is an isogram and we return true
}

And now I hope I did it correct :slight_smile:

2 Likes

I really like your aligned comments. Really easy to read!

Yeah well, I think I got a little carried away there. :slight_smile:

Privacy & Terms