-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtraTask.js
More file actions
46 lines (40 loc) · 1.04 KB
/
ExtraTask.js
File metadata and controls
46 lines (40 loc) · 1.04 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
function MatrixCoordinats(r, c, r0, c0) {
let Rezults = [];
let steps = Math.max(r, c) + 3;
Rezults.push([r0, c0]);
//turn right
c0 += 1;
Rezults.push([r0, c0]);
//turn down
r0 += 1;
Rezults.push([r0, c0]);
for (let i = 2; i <= steps; i += 2) {
//turn left
for (let j = 1; j <= i; j++) {
c0 -= 1;
Rezults.push([r0, c0]);
}
//turn up
for (let j = 1; j <= i; j++) {
r0 -= 1;
Rezults.push([r0, c0]);
}
//turn right
for (let j = 0; j <= i; j++) {
c0 += 1;
Rezults.push([r0, c0]);
}
//turn down
for (let j = 0; j <= i; j++) {
r0 += 1;
Rezults.push([r0, c0]);
}
}
let FilteredRezult = Rezults.filter(function (rezult) {
if ((rezult[0] >= 0 && rezult[0] < r) && (rezult[1] >= 0 && rezult[1] < c)) {
return true
}
});
console.log('Rezult', FilteredRezult);
}
MatrixCoordinats(5, 5, 0, 3);