forked from mishasaggi/toy-problem-workshop-tree-traversal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcar-troubled-path.js
More file actions
37 lines (33 loc) · 712 Bytes
/
car-troubled-path.js
File metadata and controls
37 lines (33 loc) · 712 Bytes
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
function carTroubledPaths(matrix){
//your code
}
//your helper functions
//given helper functions
function makeRoad(n) {
var road = []
for (var i = 0; i < n; i++) {
road.push([])
for (var j = 0; j < n; j++) {
road[i].push(false)
}
}
road.toggle = function(i, j) {
this[i][j] = !this[i][j]
}
road.hasBeenVisited = function(i, j) {
return !!this[i][j]
}
return road;
}
/*
test case:
[[0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 1, 0],
[0, 1, 1, 0, 0, 0, 1, 0]]
returns true
*/