-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest.js
29 lines (27 loc) · 858 Bytes
/
test.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 foo(arr) {
let str = arr.shift()
let pattern = arr.shift()
let r = new RegExp(pattern, "g")
for (;;) {
if (pattern === "") break
if (str.length < pattern.length * 2) break
let matches = (str.match(r) || []).filter(Boolean)
if (matches.length >= 2) {
str = str.replace(pattern, "")
str =
str.slice(0, str.lastIndexOf(pattern)) +
str.slice(str.lastIndexOf(pattern) + pattern.length)
pattern = pattern.replace(
pattern[Math.floor(pattern.length / 2)],
""
)
r = new RegExp(pattern, "g")
console.log("Shaked it.")
} else {
console.log("No shake.")
console.log(str)
break
}
}
}
foo(["##mtm!!mm.mm*mtm.#", "mtm"])