-
Notifications
You must be signed in to change notification settings - Fork 2
/
driver.js
55 lines (41 loc) · 1.29 KB
/
driver.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
var dictionary = new TrieNode();
window.onload = function() {
console.log("Onload fn check")
for (let word of wordList3){
dictionary.addWord(word);
}
}
var button = document.getElementById("submitBtn");
function prettySortAnswers(ansArray){
ansArray.sort();
ansArray.sort( (a,b) => a.length - b.length );
let n = ansArray.length;
let pretty = "<b> Words found: </b>"+ n;
let prevWord = "";
for(let word of ansArray){
if (word.length > prevWord.length){
pretty += "<br><br><b>" + word.length + " letter words: </b><br>";
}
pretty += " " + word;
prevWord = word;
}
return(pretty);
}
function onSubmit() {
try {
var str = document.getElementById("boardStr").value.toString().toLowerCase();
let aa = new Board(str);
for (let i=0; i<aa.size; i++){
for (let j=0; j<aa.size; j++){
aa.dfs( [i,j], "", new Set(), dictionary);
}
}
let ansArray = Array.from(aa.answers);
pretty = prettySortAnswers(ansArray);
document.getElementById("solutionList").innerHTML = pretty ;
}
catch(err){
console.log(err.message)
document.getElementById("solutionList").innerHTML = err.message;
}
}