-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.js
29 lines (26 loc) · 941 Bytes
/
kernel.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
function huoZiLuanYinShuDoge(frame, dictionary) {
let keywords = [];
let res = frame;
for (let typeName of Object.keys(dictionary)) {
dictionary[typeName].forEach((keyword) => {
keywords.push({ word: keyword, type: typeName });
});
}
keywords.sort((a, b) => b.word.length - a.word.length);
keywords.forEach((e) => {
res = res.replaceAll(e.word, `$${e.type.toUpperCase()}`);
});
for (let typeName of Object.keys(dictionary)) {
let i = 0;
while (true) {
i = res.indexOf(`$${typeName.toUpperCase()}`);
if (i == -1) {
break;
}
let aimNum = Math.floor(Math.random() * dictionary[typeName].length);
res = res.substring(0, i) + dictionary[typeName][aimNum] + res.substring(i + typeName.length + 1);
dictionary[typeName].splice(aimNum, 1);
}
}
return res;
};