You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like it highlights every instance of a correct letter. The actual word was shalt, but it highlighted ever S in Sassy. This is not how the original wordle works. I'm assuming that it's supposed to be like wordle, but I don't know for sure.
Anyway, great job on this!
The text was updated successfully, but these errors were encountered:
I believe the logic for this requires two passes through the guess to get the highlighting correct.
First pass: is this letter in the correct spot? If so, green. Is it completely absent from the word? If so, black.
Then, remove all the correct guesses from the answer word so they can't be reused in the comparison.
Second pass: Is this letter in the word at all? (It will necessarily be in the wrong spot.) If so, yellow. Else, black.
Edit: Here's how I solved it using the above logic:
letmutableAnswer=String(answer);constoutput=["","","","",""];constletters=guess.split("");letters.forEach((letter,index)=>{if(answer[index]===letter){mutableAnswer=mutableAnswer.replace(letter,0);//this ensures the letter won't be "in" the answer //for purposes of marking it yellow when the user guessed it in the correct position already, //without reordering the remaining letters in the answer.output[index]=green;}elseif(answer.indexOf(letter)===-1){output[index]=black;}});letters.forEach((letter,index)=>{if(!output[index]&&mutableAnswer.indexOf(letter)>-1){output[index]=yellow;mutableAnswer=mutableAnswer.replace(letter,0);}elseif(!output[index]){output[index]=black;}});returnoutput;
MikhaD
changed the title
Too much yellow highlighting
Letter in word hint not working correctly
Jan 23, 2022
The actual Wordle doesn't mark a letter as yellow unless there is at least one more of the guessed letter in the actual word in an unknown location. I just played and got the word "MANIA" as the answer. But when I guessed "INDIA," I got 🟨🟨⬛️🟩🟩 instead of ⬛️🟨⬛️🟩🟩. You can verify how the actual Wordle works by guessing primp for today's word. You'll see that the first P is black, not yellow, even though a second P exists in the word.
It looks like it highlights every instance of a correct letter. The actual word was shalt, but it highlighted ever S in Sassy. This is not how the original wordle works. I'm assuming that it's supposed to be like wordle, but I don't know for sure.
Anyway, great job on this!
The text was updated successfully, but these errors were encountered: