-
Notifications
You must be signed in to change notification settings - Fork 0
/
words.html
89 lines (75 loc) · 2.02 KB
/
words.html
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<html>
<head>
<title> Template </title>
<script src="englishWords.js"> </script>
<script>
// var allowedLetters = "dcbasuxe?1234";
// var replacements = {"nq": "1", "lq": "2", "hq": "3", "ok": "4"};
// var allowedLetters = "uiopjklmyhn-";
var allowedLetters = "etaoin";
var replacements = {};
// getAll(allowedLetters, englishWords, replacements, true).sort((a, b) => (1 - 2 * (a.length > b.length)));
// getAll(allowedLetters, englishWords, replacements, false).sort((a, b) => (1 - 2 * (a.length > b.length)));
// emoteReplaceWord();
console.log(getAll(allowedLetters, englishWords, replacements, false).sort((a, b) => (1 - 2 * (a.length > b.length))));
function getLongest(letters, words) {
var longest = [""];
for (let i in words) {
if (words[i].length >= longest[0].length) {
works = true;
for (let j in words[i]) {
if (!(letters.includes(words[i][j]))) {
works = false;
break;
}
}
if (works) {
if (words[i].length === longest[0].length) {
longest.push(words[i]);
} else {
longest = [words[i]];
}
}
}
}
return longest;
}
function getAll(letters, words, replace, m) {
const valid = [];
const r = Object.keys(replace);
for (let i in words) {
var w = words[i].toLowerCase();
for (let j in r) {
w = w.replace(r[j], replace[r[j]]);
}
works = true;
for (let j in w) {
if (!(letters.includes(w[j]))) {
works = false;
break;
}
}
if (works) {
if (m) {
valid.push(words[i]);
} else {
valid.push(w);
}
}
}
return valid;
}
const emoteReplacements = {"d": ":rankd:", "c": ":rankc:", "b": ":rankb:", "a": ":ranka:", "s": ":ranks:", "u": ":ranku:", "x": ":rankx:", "e": ":eee:", "?": ":rankz:", "1": ":nq:", "2": ":lq:", "3": ":hq:", "4": ":ok:"};
function emoteReplaceWord(word) {
let w = "";
for (i in word) {
w += emoteReplacements[word[i]];
}
return w;
}
</script>
</head>
<body>
</body>
</html>