Last active
January 17, 2022 13:55
-
-
Save kbravh/a52f281aea9bd4e85d492eeb2159725f to your computer and use it in GitHub Desktop.
Displays the Wordle-style line of emojis for a given guess and solution. Cassidoo newsletter #231
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wordleGuess = (guess, solution) => | |
[...guess].map((letter, i) => | |
solution[i] === letter ? 'π©' | |
: solution.includes(letter) && | |
guess.slice(0, i + 1).split(letter).length -1 <= solution.split(letter).length - 1 ? 'π¨' | |
: 'β¬').join('') | |
const solutionWord = 'fudge' | |
console.log(wordleGuess('reads', solutionWord)) // β¬π¨β¬π¨β¬ | |
console.log(wordleGuess('lodge', solutionWord)) // β¬β¬π©π©π© | |
// See https://www.reddit.com/r/wordle/comments/ry49ne/illustration_of_what_happens_when_your_guess_has/ | |
// for rules on repeated letters. | |
console.log(wordleGuess('deeds', solutionWord)) // π¨π¨β¬β¬β¬ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment