TArray<FString> UBullCowCartridge::GetValidWords(TArray<FString> RawWords) const {
//Empty array of string
TArray<FString> ValidWords;
for (int32 i = 0; i < RawWords.Num(); i++)
{
// PrintLine(TEXT("Print out word %i is %s"), i, *Words[i]);
if (Words[i].Len() >= 4 && Words[i].Len() <= 8 && IsIsogram(Words[i]) == false) {
//Append to array
ValidWords.Emplace(Words[i]);
// PrintLine(TEXT("it's length is: %i, the word is: %s."), Words[i].Len(), *Words[i]);
}
}
return ValidWords;
}
As i understand, each time you call .Len() C++ perform new operation and recalculate the length of given string. And it’s true for taking word from list with WordList[Index]. So i pass this two operations to variables, and in my code this operations calls once per word.
Yeah Fair Play. The Collection Loop is nice code to read. When you need to be selective of the index then you would need the “for loop” to be optimized. in this case we need to read the entirety to check length and type.