-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
55 lines (49 loc) · 1.77 KB
/
index.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Words with letters</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
h2 {
margin-top: 0;
margin-bottom: 0.5rem;
}
#result {
white-space: pre-line;
margin-top: 0.5rem;
}
</style>
</head>
<body>
<form>
<h2>Words with letters</h2>
<input id="letters" type="text" autofocus>
<button type="submit">Find</button>
<button id="findWithAllCharacters" type="button">Find with all characters</button>
</form>
<div id="result"></div>
<script type="module" src="index.js"></script>
<script type="module">
import { generateSearchTree, findWordsThatCanBeMadeOutOfCharacters, findWordsWithCharacters } from './index.js'
import { words } from './words.js'
const searchTree = generateSearchTree(words)
const $form = document.querySelector('form')
const $letters = document.querySelector('#letters')
const $result = document.querySelector('#result')
$form.addEventListener('submit', function onSubmit(event) {
event.preventDefault()
const characters = $letters.value.split('')
const words = findWordsThatCanBeMadeOutOfCharacters(searchTree, characters)
$result.textContent = words.join('\n')
})
const $findWithAllCharacters = document.querySelector('#findWithAllCharacters')
$findWithAllCharacters.addEventListener('click', function onFindWithAllCharacters() {
event.preventDefault()
const characters = $letters.value.split('')
const words = findWordsWithCharacters(searchTree, characters)
$result.textContent = words.join('\n')
})
</script>
</body>
</html>