Skip to content

Instantly share code, notes, and snippets.

@wondermike221
Created April 20, 2023 15:36
Show Gist options
  • Save wondermike221/2d305c11b013d757a8ce8c432d6d0896 to your computer and use it in GitHub Desktop.
Save wondermike221/2d305c11b013d757a8ce8c432d6d0896 to your computer and use it in GitHub Desktop.
Helper function to filter the all wordle list.
// Use on https://raw.githubusercontent.com/chidiwilliams/wordle/main/src/data/words.json
const preTag = document.querySelector('pre');
const all = JSON.parse(preTag.textContent);
/**
* 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