/
kata-six.js
61 lines (54 loc) · 1.6 KB
/
kata-six.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
55
56
57
58
59
60
61
const whereCanIPark = function(spots, vehicle) {
for (let y = 0; y < spots.length; y++) { // loop thru (y) array
for (let x = 0; x < spots[y].length; x++) { // loop thru values inside of the array
const spot = spots[y][x]; // create a variable for condition
if (vehicle === "regular") { // check for condition
if (spot === "R") {
return [x, y]; // returns the values(position in the array) if conditions are met
}
} else if (vehicle === "small") {
if (spot === "R" || spot === "S") {
return [x, y];
}
} else if (vehicle === "motorcycle") {
if (spot === "M" || spot === "S" || spot === "R") {
return [x, y];
}
}
}
}
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'
));