-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithms.js
More file actions
69 lines (56 loc) · 2.5 KB
/
algorithms.js
File metadata and controls
69 lines (56 loc) · 2.5 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
/* jshint esversion: 6 */
let ref = firebase.database().ref('/algorithms/').orderByChild('name');
let cards = document.getElementById('cards');
ref.once('value').then((snapshot)=>{
console.log(snapshot.val());
for (const key in snapshot.val()) {
let algorithm = snapshot.val()[key];
cards.appendChild(createAlgorithmCard(algorithm, key));
}
});
var createAlgorithmCard = function(algorithm, id){
var container = document.createElement("DIV");
var header = document.createElement("DIV");
var icon = document.createElement("I");
var cardbody = document.createElement("DIV");
var className = document.createElement("P");
var strategy = document.createElement("P");
var asyptoticComplexitiesLabel = document.createElement("P");
var asyptoticComplexities = document.createElement("UL");
var bestCase = document.createElement("li");
var averageCase = document.createElement("li");
var worstCase = document.createElement("li");
var pseudocode = document.createElement("P");
var facts = document.createElement("P");
container.className = "card algo-card";
header.className = "card-header";
icon.className = "fa fa-edit float-right icon-button";
cardbody.className = "card-body";
header.innerHTML = algorithm.name;
className.innerHTML = "Class: " + algorithm.class;
strategy.innerHTML = "Strategy: " + algorithm.strategy;
asyptoticComplexitiesLabel.innerHTML = "Asyptotic Complexites: ";
bestCase.innerHTML = "Best case: " + algorithm.bestCase;
averageCase.innerHTML = "Average case: " + algorithm.averageCase;
worstCase.innerHTML = "Worst case: " + algorithm.worstCase;
pseudocode.innerHTML = "Pseuodcode: <pre><code>" + algorithm.pseudocode + "</pre></code>";
var factsText = algorithm.facts.replace(/\n/g, "<br />");
facts.innerHTML = "Facts: "+ '<br>' + factsText;
icon.addEventListener('click', () => {
sessionStorage.setItem('editAlgorithmId', id);
window.location = "addalgorithm.html";
});
header.appendChild(icon);
asyptoticComplexities.appendChild(bestCase);
asyptoticComplexities.appendChild(averageCase);
asyptoticComplexities.appendChild(worstCase);
cardbody.append(className);
cardbody.append(strategy);
cardbody.append(asyptoticComplexitiesLabel);
cardbody.append(asyptoticComplexities);
cardbody.append(pseudocode);
cardbody.append(facts);
container.append(header);
container.append(cardbody);
return container;
};