Created
April 11, 2019 15:37
-
-
Save MapleCCC/36cbc0e28d47218c5914dbc1dcc6dfe8 to your computer and use it in GitHub Desktop.
Generate intelligent random words
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
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