Created
August 9, 2024 10:37
-
-
Save netcall-jlo/11f03fa099a9a262592d7e230a569309 to your computer and use it in GitHub Desktop.
Notes about a remake of https://www.merriam-webster.com/games/blossom-word-game/ to use for practice
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
// https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json | |
var list = JSON.parse(document.querySelector("pre").textContent); | |
var allWords = Object.keys(list); | |
var allowed = allWords.filter(({ length }) => length > 3); | |
function increaseLetterCount(letters, letter) { | |
if (!letters[letter]) { | |
letters[letter] = 0; | |
} | |
letters[letter] += 1; | |
return letters; | |
} | |
function getLetterCounts(word) { | |
return word.split("").reduce(increaseLetterCount, Object.create(null)); | |
} | |
function getLetters(word) { | |
return Object.keys(getLetterCounts(word)); | |
} | |
var letterCounts = allowed.reduce( | |
(list, word) => { | |
list[word] = getLetters(word) | |
return list; | |
}, | |
Object.create(null), | |
); | |
var pangrams = Object | |
.entries(letterCounts) | |
.filter(([ignore, { length }]) => length === 7) | |
.map(([word]) => word); | |
function random() { | |
return window.crypto.getRandomValues(new Uint32Array(1))[0] / (2**32); | |
} | |
function getStartingLetters(pangrams) { | |
return getLetters(pangrams[Math.floor(random() * pangrams.length)]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment