-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearnNormal.js
More file actions
42 lines (34 loc) · 1.2 KB
/
learnNormal.js
File metadata and controls
42 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var fs = require('fs');
var readline = require('readline');
var normalWords = require('./dictionary/normal-words.json').dictionary;
var normalWordMap = {};
for (var index in normalWords)
normalWordMap[normalWords[index]] = true;
console.log('TYPE THE YOU THINK ARE IT MIGHT BE');
console.log('NOT REGISTERED NORMAL WORDS.');
console.log("IF YOU TYPE THE 'SAVE' SO WILL BE JSON CHANGED.\n");
var line = readline.createInterface({
input: process.stdin,
output: process.stdout
});
line.on('line', (input) => {
if (input.toLowerCase() == 'save') {
let sortednormalWordMap = {};
Object.keys(normalWordMap).sort().forEach(function(key) {
sortednormalWordMap[key] = normalWordMap[key];
});
let list = [];
for (var index in sortednormalWordMap) list.push(index);
fs.writeFile('./dictionary/normal-words.json', JSON.stringify({
dictionary: list
}, null, 4));
console.log('[DICTIONARY UPGRADED]');
return;
}
if (typeof(normalWordMap[input]) == 'undefined') {
normalWordMap[input] = true;
console.log('[NEW WORD FOUNDED]');
} else {
console.log('[WORD HAS ALREADY FOUNDED]');
}
});