-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcode_convert.html
More file actions
executable file
·259 lines (234 loc) · 7.03 KB
/
Copy pathlcode_convert.html
File metadata and controls
executable file
·259 lines (234 loc) · 7.03 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Lcode List</title>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="lcode_convert.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="lcode.json"></script>
</head>
<!-- The `multiple` attribute lets users select multiple files. -->
<body style="text-align: center" id="body">
<h1 style="color: rgb(20, 79, 146)">Lcode List</h1>
<span
id="lcode_count_easy"
style="
color: rgba(15, 172, 54, 0.795);
font-size: 15px;
font-weight: 700;
margin: 5px;
"
>AAA</span
>
<span
id="lcode_count_medium"
style="
color: rgba(197, 149, 44, 0.795);
font-size: 15px;
font-weight: 700;
margin: 5px;
"
>AAA</span
>
<span
id="lcode_count_hard"
style="
color: rgba(214, 68, 31, 0.795);
font-size: 15px;
font-weight: 700;
margin: 5px;
"
>AAA</span
>
<div
id="lcode_count"
style="
color: rgb(71, 94, 95);
font-size: 18px;
font-weight: bold;
margin: 10px;
"
>
AAA
</div>
<div
id="tagList"
style="
color: rgb(141, 118, 204);
font-size: 18px;
font-weight: bold;
margin: 10px;
"
></div>
<table
align="center"
id="table"
border="1"
class="table table-bordered table-hover"
></table>
<script>
var lcodeData = JSON.parse(lcode_data);
// console.log("Lcode:", lcodeData);
var el_up = document.getElementById("GFG_UP");
var list = [
{
Number: "0704",
Level: 1,
Title: "Binary Search",
Url: "https://leetcode.com/problems/binary-search",
Tags: ["Binary Search", "DFS"],
Memo: "Watch out the condition to jump out the loop.",
},
{
Number: "0705",
Level: 1,
Title: "Design HashSet",
Url: "https://leetcode.com/problems/design-hashset",
Tags: ["Binary Search", "Hash Set"],
Memo: "Compare set and map.",
},
{
Number: "0706",
Level: 1,
Title: "Design HashMap",
Url: "https://leetcode.com/problems/design-hashmap",
Tags: ["Data Structure", "Hash Map"],
Memo: "Implement the hashmap from linkedlist and array.",
},
{
Number: "0718",
Level: 2,
Title: "Maximum Length of Repeated Subarray",
Url: "https://leetcode.com/problems/maximum-length-of-repeated-subarray",
Tags: ["Array", "String"],
Memo: "--",
},
];
list = lcodeData;
var selectedTag = [];
var allTags = ["Graph", "BFS", "DFS", "Binary Search", "Island", "Union-Find", "Heap", "SSSP", "Trie", "Tree"];
// el_up.innerHTML = "Click on the button to create "
// + "the table from the JSON data.<br><br>"
// + JSON.stringify(lcode) + "<br>";
var count_easy = 0;
var count_medium = 0;
var count_hard = 0;
var count_total = 0;
function constructTable(selector) {
// Getting the all column names
var cols = Headers(list, selector);
// Traversing the JSON data
for (var i = 0; i < list.length; i++) {
var row = $("<tr/>");
// console.log(list[i]);
number = list[i]["Number"];
level = list[i]["Level"];
title = list[i]["Title"];
url = list[i]["Url"];
tags = list[i]["Tags"];
memo = list[i]["Memo"];
var isFilterKept = false;
for (var tag of tags) {
if (selectedTag.includes(tag)) {
isFilterKept = true;
}
}
if (isFilterKept === false && selectedTag.length != 0) {
console.log(">>>>Skip:", number);
continue;
}
console.log(number);
//console.log(number, level, title, url);
//Number
var colorCode;
if (level == 1) {
colorCode = "rgba(15, 172, 54, 0.795)";
count_easy += 1;
} else if (level == 2) {
colorCode = "rgba(230, 182, 80, 0.795)";
count_medium += 1;
} else {
colorCode = "rgba(214, 68, 31, 0.795)";
count_hard += 1;
}
row.append(
$("<td/>")
.css("background-color", colorCode)
.html("<div>" + number + "</div>")
);
//Title
row.append(
$("<td/>").html(
'<a href="' + url + '" class="large-font"> ' + title + "</a>"
)
);
//Tags
var tagsHtml = "";
for (var tag of tags) {
tagsHtml =
tagsHtml +
'<button class="btn btn-primary tag" style="margin:5px" id="' +
tag +
'">' +
tag +
"</button>";
}
tagsHtml = tagsHtml + "";
row.append($("<td/>").html(tagsHtml));
//Memo
row.append(
$("<td/>").html('<p style = "font-size:small">' + memo + "</p>")
);
// Adding each row to the table
$(selector).append(row);
}
}
function Headers(list, selector) {
var columns = ["Number", "Title", "Tag", "Memo"];
var header = $("<tr/>");
for (var k of columns) {
header.append($("<th/>").html(k));
}
// Appending the header to the table
$(selector).append(header);
return columns;
}
constructTable("#table");
count_total = count_easy + count_medium + count_hard;
$("#lcode_count_easy").html("Easy:" + count_easy);
$("#lcode_count_medium").html("Medium:" + count_medium);
$("#lcode_count_hard").html("Hard:" + count_hard);
$("#lcode_count").html("Total:" + count_total);
document.querySelectorAll(".tag").forEach((item) => {
item.addEventListener("click", function () {
if (selectedTag.includes(item.id)) {
return;
}
selectedTag.push(item.id);
var tagsHtml = "";
for (var tag of selectedTag) {
tagsHtml =
tagsHtml +
'<button class="btn btn-secondary tag" style="margin:5px" id="' +
tag +
'">' +
tag +
"</button>";
}
tagsHtml = tagsHtml + "";
$("#tagList").html(tagsHtml);
$("#table").html("");
constructTable("#table");
console.log("click on:" + item.id);
console.log(selectedTag);
});
});
</script>
</body>
</html>