Created
August 14, 2023 16:52
-
-
Save wondermike221/f055e78178aeeb7bbecc94669a3b252d to your computer and use it in GitHub Desktop.
Wordle Finder
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
// Use on https://raw.githubusercontent.com/chidiwilliams/wordle/main/src/data/words.json | |
let dataURL = 'https://raw.githubusercontent.com/chidiwilliams/wordle/main/src/data/words.json'; | |
let preTag, all; | |
async function getData() { | |
if(window.location.href == dataURL) { | |
preTag = document.querySelector('pre'); | |
all = JSON.parse(preTag.textContent); | |
} else { | |
const response = await fetch(dataURL); | |
const words = await response.json(); | |
all = words; | |
} | |
} | |
getData(); | |
/** | |
* Filters the all array to return only the wordles that match the given criteria. | |
* @param excludedLetters String of letters to exclude from the wordle. | |
* @param includedLetters String of letters to include in the wordle. | |
* @param positionalChecks Function that takes a item and returns true if it passes the positional checks. e.g. (item) => item[0] === 'a' && item[1] === 'b' | |
* @returns String[] of possible wordles. | |
*/ | |
function getPossibleWordles(excludedLetters, includedLetters, positionalChecks){ | |
let filtered = all.filter((item) => { | |
for(let excluded of excludedLetters){ | |
if(item.includes(excluded)){ | |
return false; | |
} | |
} | |
for(let included of includedLetters){ | |
if(!item.includes(included)){ | |
return false; | |
} | |
} | |
return (positionalChecks(item)); | |
}) | |
return filtered; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment