Comments (2)
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:
let mutableAnswer = String(answer);
const output = ["", "", "", "", ""];
const letters = 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;
} else if (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);
} else if (!output[index]) {
output[index] = black;
}
});
return output;
from wordle.
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.
~ Courtesy of flyguy33443322 on reddit.
from wordle.
Related Issues (20)
- Remove Google HOT 4
- Doesn't work on ipad 15.5 HOT 3
- Grid is too dense HOT 4
- Swipe between modes
- Option to disable background symbols HOT 3
- Feature request: Option to Disable Keyboard color assist HOT 2
- Help HOT 1
- Board keeps condensing HOT 4
- New Issue
- Multilanguage support HOT 4
- DOESNT GO ON AND ON HOT 5
- Board Layout Issues on new iOS devices & very old devices HOT 3
- Missing sourcemap warnings when dev site is first loaded. HOT 2
- Use State design pattern
- Adding swipe detection on board has disabled context menu
- Feature request: i18n support HOT 2
- Import / Export game data
- infinite does not work HOT 1
- Historical game numbers are wrong HOT 1
- Potential answer / guess count displayed 0 for "Dolly"
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wordle.