-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProblem3.js
More file actions
63 lines (53 loc) · 1.47 KB
/
Problem3.js
File metadata and controls
63 lines (53 loc) · 1.47 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
/*
Zombie Paths!!!
You are given an array of arrays
[
['a', 'b', 300],
['b', 'c', 12],
['a', 'd', 32],
['d', 'c', 30],
['b', 'e', 3000],
['d', 'e', 1000]
]
Position[0] = a street corner
Position[1] = a connecting street corner
Position[2] = Number of zombies between street corners
You have a zombie blaster, which you can only use once to BLAST away
all of the zombies.
Find the shortest path from point 'a' to 'e'
*/
var ds = require('./ds');
var Graph = ds.Graph;
var /* MYSTERY DS */ = ds./* MYSTERY DS */;
var zombiePaths = function (map, start, end) {
// TODO: Implement
};
/////////////////////////////////////////////////////////////
// TESTS
/////////////////////////////////////////////////////////////
var testCases = require('./test/problem3cases');
testCases.forEach(function (tcase) {
console.log('Test Case, ', tcase);
console.log(zombiePaths(tcase, 'a', 'e'));
});
/////////////////////////////////////////////////////////////
// HELPERS
/////////////////////////////////////////////////////////////
var parseMap = function (map) {
var graph = new Graph();
map.forEach(function (testCase) {
graph.addEdge(testCase[0], testCase[1], testCase[2]);
});
return graph;
};
var copy = function (extendingObj) {
var copy = {};
for (var key in extendingObj) {
if (Array.isArray(extendingObj[key])) {
copy[key] = extendingObj[key].slice();
} else {
copy[key] = extendingObj[key];
}
}
return copy;
};