Skip to content

Instantly share code, notes, and snippets.

@MapleCCC
Created April 11, 2019 15:37
Show Gist options
  • Save MapleCCC/36cbc0e28d47218c5914dbc1dcc6dfe8 to your computer and use it in GitHub Desktop.
Save MapleCCC/36cbc0e28d47218c5914dbc1dcc6dfe8 to your computer and use it in GitHub Desktop.
Generate intelligent random words
var genRandomWords = require("rword").rword.generate;
var mostMistypedLetter = "";
var mostMistypedCount = 0;
for (var [key, value] of result.miss) {
if (mostMistypedCount < value) {
mostMistypedCount = value;
mostMistypedLetter = key;
}
}
var firstQuery = mostMistypedLetter + ".*" + mostMistypedLetter + ".*" + mostMistypedLetter;
var secondQuery = mostMistypedLetter + ".*" + mostMistypedLetter;
var thirdQuery = mostMistypedLetter;
var newWord = genRandomWords(1, { contains: firstQuery });
if (newWord === "") {
newWord = genRandomWords(1, { contains: secondQuery });
}
if (newWord === "") {
newWord = genRandomWords(1, { contains: thirdQuery });
}
if (newWord === "") {
newWord = genRandomWords(1);
}
res.json({ word: newWord });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment