Skip to content

Instantly share code, notes, and snippets.

@kbravh
Last active January 17, 2022 13:55
Show Gist options
  • Save kbravh/a52f281aea9bd4e85d492eeb2159725f to your computer and use it in GitHub Desktop.
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
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