-
Notifications
You must be signed in to change notification settings - Fork 0
/
park.js
54 lines (51 loc) · 1.45 KB
/
park.js
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
const whereCanIPark = function(spots, vehicle) {
for (var row = 0; row < spots.length; row++) {
for (var column = 0; column < spots[row].length; column++) {
console.log(spots[row][column] );
if (vehicle === "regular" && spots[row][column] === "R") {
return [column, row];
} else if ((spots[row][column] === "S" || spots[row][column] === "R") && (vehicle === "small")) {
return [column, row];
} else if ((spots[row][column] === "M" || spots[row][column] === "S" || spots[row][column] === "R") && (vehicle === "motorcycle")){
return [column, row];
}
// else {
// console.log("never");
// return false;
// }
}
}
}
console.log(whereCanIPark(
[
// COLUMNS ARE X
// 0 1 2 3 4 5
['s', 's', 's', 'S', 'R', 'M'], // 0 ROWS ARE Y
['s', 'M', 's', 'S', 'r', 'M'], // 1
['s', 'M', 's', 'S', 'r', 'm'], // 2
['S', 'r', 's', 'm', 'r', 'M'], // 3
['S', 'r', 's', 'm', 'r', 'M'], // 4
['S', 'r', 'S', 'M', 'M', 'S'] // 5
],
'regular'
));
console.log(whereCanIPark(
[
['M', 'M', 'M', 'M'],
['M', 's', 'M', 'M'],
['M', 'M', 'M', 'M'],
['M', 'M', 'r', 'M']
],
'small'
));
console.log(whereCanIPark(
[
['s', 's', 's', 's', 's', 's'],
['s', 'm', 's', 'S', 'r', 's'],
['s', 'm', 's', 'S', 'r', 's'],
['S', 'r', 's', 'm', 'r', 's'],
['S', 'r', 's', 'm', 'R', 's'],
['S', 'r', 'S', 'M', 'm', 'S']
],
'motorcycle'
))