-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (56 loc) · 1.98 KB
/
index.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Converte o txt para json
const fs = require("fs");
const raw = fs.readFileSync("./palavras.txt").toString().replace('\r', '');
const data = raw.split("\n");
const headers = data.shift().split("|");
let json = [];
for (let i = 0; i < data.length; i++) {
if (/^\s*$/.test(data[i])) continue;
const contentCells = data[i].split("|");
let jsonLine = {};
for (let i = 0; i < contentCells.length; i++)
jsonLine[headers[i]] = contentCells[i];
json.push(jsonLine);
}
// Filtros
let filtroTamanho, filtroChars = [];
json.forEach(entrada => {
let tamanhoPalavra = entrada.palavra;
tamanhoPalavra = tamanhoPalavra.length;
let specialChars = ['ç', 'ã', 'á', 'é', 'ê', 'í', 'ó', 'ô', 'õ', 'ú']
let commonChars = ['c', 'a', 'a', 'e', 'e', 'i', 'o', 'o', 'o', 'u']
const replaceSpecialChars = sc => {
let cc = commonChars[specialChars.indexOf(sc)];
entrada.palavra = entrada.palavra.replace(sc, cc);
}
if (tamanhoPalavra === 8) {
specialChars.forEach(sc => replaceSpecialChars(sc))
filtroTamanho.push(entrada.palavra.slice(0, -1));
}
});
filtroTamanho.forEach(entrada => {
entrada = entrada.toLowerCase();
let possiblePos = [3, 5, 6];
let possibleLetters = ["i", "e", "a", "s", "b", "t", "o"];
let possibleNumbers = ["1", "3", "4", "5", "6", "7", "0"];
let entradaScore = 0;
const testChar = pos => {
possibleLetters.forEach(letter => {
let index = possibleNumbers[possibleLetters.indexOf(letter)];
entrada.charAt(pos) == letter && (entrada = entrada.substring(0, pos) + index + entrada.substring(pos + 1), entradaScore++);
})
}
possiblePos.forEach(pos => testChar(pos))
entradaScore === 3 && filtroChars.push(entrada.toUpperCase());
});
const listaFinal = JSON.stringify(filtroChars);
function writeNewFile() {
fs.writeFile("./lista-final.json", listaFinal, "utf8", function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
}
// Reescrever arquivo lista-final
writeNewFile();