My attempt to make the IsIsogram function recursive

Hello,

I got a bit carried away with the task and instead of doing the pseudo code I actually went ahead and did the whole thing. And just for the extra challenge I tried to do it recursively instead of using a loop.

If anyone sees this I’d like to hear some input on ways to improve the function.

bool UBullCowCartridge::IsIsogram(FString Guess)
{
    return !IsSameCharacter(Guess, 0);
}


bool UBullCowCartridge::IsSameCharacter(FString Guess, int32 Index)
{
    int32 GuessMaxIndex = Guess.Len()-2;

    if(Guess[Index] == Guess [Index+1])
    {
        return true;
    }

    if(Index == GuessMaxIndex)
    {
        return false;
    }

    IsSameCharacter(Guess, Index+1);
    return true;
}
1 Like

Always do extra challenges. They help learning and processing the information!

Privacy & Terms