-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (52 loc) · 1.04 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
const items = [
"apple",
"ape",
"apricot",
"banana",
"banyan",
"pear",
"peach",
"guava",
"goal",
"cherry",
"orange",
"orangotan",
"pineapple",
"pink",
"mango",
"man",
"grapes",
"gum",
"blueberry",
"raspberry",
"melon",
"muskmelon",
"blackberry",
"plum",
"pluck",
"kiwi",
"knife",
"peach",
"strawberry",
"avocado",
"armadillo",
];
const root = new makeNode("\0");
for (const item of items) add(item, 0, root);
const text_box = document.getElementById("text-box");
const list = document.getElementById("list");
function handler(e) {
const str = e.target.value;
const predictions = search(str, 0, root);
console.log(predictions);
list.innerHTML = "";
for (const prediction of predictions)
list.innerHTML += `<li class="list-group-item clickable" onclick="handleClick(this)"><b>${str}</b>${prediction.substring(
str.length
)}</li>`;
}
function handleClick(e) {
text_box.value = e.innerText;
}
handler({ target: { value: "" } });
text_box.addEventListener("keyup", handler);