Skip to content

Instantly share code, notes, and snippets.

@kabeer11000
Created August 30, 2023 00:46
Show Gist options
  • Save kabeer11000/e0806405f7066278a0c8935f792facff to your computer and use it in GitHub Desktop.
Save kabeer11000/e0806405f7066278a0c8935f792facff to your computer and use it in GitHub Desktop.
Scrabble Bi-Grams based word prediction
const validWords = ["dog", "dough", "doggy", "doodle", "dig", "door"];
const bigrams = ["do", "og"]; // Example bigram array
function generateValidWordsFromBigrams(bigrams, validWords) {
const validGeneratedWords = [];
for (const word of validWords) {
const isValid = bigrams.every(bigram => word.includes(bigram));
if (isValid) {
validGeneratedWords.push(word);
}
}
return validGeneratedWords;
}
// filter words by rack
const validGeneratedWords = generateValidWordsFromBigrams(bigrams, validWords);
console.log(validGeneratedWords);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment