-
Notifications
You must be signed in to change notification settings - Fork 0
/
pract0617.js
69 lines (64 loc) · 1.59 KB
/
pract0617.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
62
63
64
65
66
67
68
69
const generate2DArray = (n) => {
let arr = new Array(n);
for (let i = 0; i < n; i++) {
arr[i] = new Array(n);
}
return arr;
};
const randomNumb = (arr) => {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
arr[i][j] = Math.floor(Math.random() * 3 + 1);
}
}
return arr;
};
const verticalArray = (arr) => {
let exist = false;
let count = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (arr[i][j] === 2 && (arr[i][j - 1]) === 1 && (arr[i][j + 1]) === 3) {
count++;
exist = true;
}
}
}
return [exist, count];
};
const horizontalArray = (arr) => {
let exist = false;
let count = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (i > 1) {
if (arr[i][j] === 3 && (arr[i - 1][j] === 2 && (arr[i - 2][j] === 1))) {
exist = true;
count++;
}
}
}
}
return [exist, count];
};
const searchLArray = (arr) => {
let exist = false;
let count = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (i > 0 && j > 0) {
if (arr[i][j] === 3 && arr[i - 1][j] === 2 && arr[i - 1][j - 1] === 1) {
exist = true;
count++;
}
}
}
}
return [exist, count];
};
let tomb = generate2DArray(20);
randomNumb(tomb);
console.log(tomb);
console.log('Vertikális 123 van-e?', verticalArray(tomb));
console.log('Horizontáliks 123 van-e?', horizontalArray(tomb));
console.log('L betű 123', searchLArray(tomb));