-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (35 loc) · 958 Bytes
/
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
// Project: thai-cut-slim
// CreatedBy: Comdevx
// Email: [email protected]
// Created: 2019/10/25
// Facebook: http://www.fb.com/comdevx
const fs = require('fs')
require.extensions['.txt'] = function (module, filename) {
module.exports = fs.readFileSync(filename, 'utf8')
}
let d = require("./dict.txt")
d = d.split('\n')
exports.addon = (l) => {
d = d.concat(l)
}
exports.cut = (w) => {
const arr = []
for (let i = 0; i < w.length;) {
let sub = []
d.forEach(v2 => {
if (w[i] + w[i + 1] === v2[0] + v2[1]) sub.push([v2, v2.length])
})
sub.sort((a, b) => b[1] - a[1])
for (let ii = 0; ii < sub.length; ii++) {
const l = sub[ii][1] + i
const s = w.substring(i, l)
if (sub[ii][0] === s) {
i = l - 1
arr.push(s)
ii = sub.length
}
}
i++
}
return arr
}