Created
March 5, 2022 21:23
-
-
Save jesboat/5aae59db69fdc3d4c505e8e06e923037 to your computer and use it in GitHub Desktop.
This file contains 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
if (this.hardMode) { | |
var t = ( | |
function() { | |
var thisGuess = s; | |
var previousGuess = this.boardState[this.rowIndex - 1]; | |
var previousEvaluation = this.evaluations[this.rowIndex - 1]; | |
if (!thisGuess || !previousGuess || !previousEvaluation) { | |
return { | |
validGuess: true, | |
}; | |
} | |
for (var pos = 0; pos < previousEvaluation.length; pos++) { | |
if (previousEvaluation[pos] === CORRECT && thisGuess[pos] !== previousGuess[pos]) { | |
return { | |
validGuess: false, | |
errorMessage: "".concat($a(pos + 1), " letter must be ").concat(previousGuess[pos].toUpperCase()) | |
}; | |
} | |
} | |
var letterCountsInPreviousGuess = {}; | |
for (var pos = 0; pos < previousEvaluation.length; pos++) { | |
if ([CORRECT, PRESENT].includes(previousEvaluation[pos])) { | |
if (letterCountsInPreviousGuess[previousGuess[pos]]) { | |
letterCountsInPreviousGuess[previousGuess[pos]] += 1; | |
} else { | |
letterCountsInPreviousGuess[previousGuess[pos]] = 1; | |
} | |
} | |
} | |
var letterCountsInThisGuess = thisGuess.split("").reduce( | |
(function(letterCountsInThisGuess, letter) { | |
if (letterCountsInThisGuess[letter]) { | |
letterCountsInThisGuess[letter] += 1; | |
} else { | |
letterCountsInThisGuess[letter] = 1; | |
} | |
return letterCountsInThisGuess; | |
}), | |
{} | |
); | |
for (var letter in letterCountsInPreviousGuess) { | |
if ((letterCountsInThisGuess[letter] || 0) < letterCountsInPreviousGuess[i]) { | |
return { | |
validGuess: false, | |
errorMessage: "Guess must contain ".concat(letter.toUpperCase()) | |
}; | |
} | |
} | |
return { | |
validGuess: true | |
} | |
}() | |
) | |
, n = t.validGuess | |
, o = t.errorMessage; | |
if (!n) | |
return a.setAttribute("invalid", ""), | |
void this.addToast(o || "Not valid in hard mode") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment