Skip to content

Commit

Permalink
Extended layout to allow for more than one section.
Browse files Browse the repository at this point in the history
  • Loading branch information
fhd committed May 5, 2011
1 parent f027aa4 commit e0acb2b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
1 change: 0 additions & 1 deletion TODO.md
@@ -1,4 +1,3 @@
- Extend layout to allow for more than one section
- Implement non-comparison sort algorithms (e.g. counting sort)
- Implement selection problem alrogithms (randomized select and select)
- Implement data structures
Expand Down
72 changes: 39 additions & 33 deletions server.js
@@ -1,37 +1,43 @@
var algorithms = {
insertionSort: {
name: "Insertion Sort",
description: "A simple sort algorithm, works like most people sort cards on their hand.",
category: "sorting"
},
mergeSort: {
name: "Merge Sort",
description: "A fast, recursive sort algorithm that divides and merges the input.",
category: "sorting"
},
bubbleSort: {
name: "Bubble Sort",
description: "An extremely simple sort algorithm with so abysmal performance that this demonstration doesn't show every step.",
category: "sorting"
},
heapsort: {
name: "Heapsort",
description: "A well performing sort algorithm that uses a binary heap.",
category: "sorting"
},
quicksort: {
name: "Quicksort",
description: "A fast, recursive sort algorithm that partitions the input.",
category: "sorting"
},
randomizedQuicksort: {
name: "Randomized Quicksort",
description: "A variant of Quicksort that avoids the worst case running time by partitioning around a random pivot element.",
category: "sorting"
var categories = {
sorting: {
name: "Sorting",
algorithms: {
insertionSort: {
name: "Insertion Sort",
description: "A simple sort algorithm, works like most people sort cards on their hand.",
},
mergeSort: {
name: "Merge Sort",
description: "A fast, recursive sort algorithm that divides and merges the input.",
},
bubbleSort: {
name: "Bubble Sort",
description: "An extremely simple sort algorithm with so abysmal performance that this demonstration doesn't show every step.",
},
heapsort: {
name: "Heapsort",
description: "A well performing sort algorithm that uses a binary heap.",
},
quicksort: {
name: "Quicksort",
description: "A fast, recursive sort algorithm that partitions the input.",
},
randomizedQuicksort: {
name: "Randomized Quicksort",
description: "A variant of Quicksort that avoids the worst case running time by partitioning around a random pivot element.",
}
}
}
};

var $ = require("jquery");
var $ = require("jquery"), algorithms = {};

$.each(categories, function (categoryKey, category) {
$.each(category.algorithms, function(algorithmKey, algorithm) {
algorithm.category = categoryKey;
algorithms[algorithmKey] = algorithm;
});
});

$.each(algorithms, function (key, value) {
value.file = key + ".js";
Expand Down Expand Up @@ -60,7 +66,7 @@ app.configure("production", function() {
});

app.get("/", function(req, res) {
res.render("index", {"algorithms": algorithms});
res.render("index", {"categories": categories});
});

var fs = require("fs");
Expand All @@ -72,7 +78,7 @@ app.get("/:algorithm", function(req, res) {
+ "/" + algorithm.file);
res.render(algorithm.category, {
currentAlgorithm: algorithm,
"algorithms": algorithms
"categories": categories
});
} else
res.send(404);
Expand Down
11 changes: 6 additions & 5 deletions views/layout.jade
Expand Up @@ -24,10 +24,11 @@ html
| .

nav
h3 Sorting
ul
- each algorithm in algorithms
li
a(href=algorithm.url)= algorithm.name
- each category in categories
h3= category.name
ul
- each algorithm in category.algorithms
li
a(href=algorithm.url)= algorithm.name

div#content!= body

0 comments on commit e0acb2b

Please sign in to comment.