Skip to content

Instantly share code, notes, and snippets.

@J3698
Last active June 4, 2019 00:40
Show Gist options
  • Save J3698/69dd4339789fb0e053d8dc6a3ccd64f2 to your computer and use it in GitHub Desktop.
Save J3698/69dd4339789fb0e053d8dc6a3ccd64f2 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const alph = 'abcdefghijklmnopqrstuvwxyz'
try {
var fileContents = fs.readFileSync('./dictionary.txt', 'utf8');
} catch(err) {
throw "Dictionary file does not exist";
}
var words = fileContents.split('\n');
words = cleanWords(words);
var chain = createChain(words);
// this is exposed to people using the package
exports.randomWord = function(length) {
if (typeof length != "number") {
throw "randomWord expects a number"
} else if (length < 2) {
throw "length must be at least 2"
}
return randomWord(chain, length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment