-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomework0617.js
More file actions
36 lines (32 loc) · 746 Bytes
/
homework0617.js
File metadata and controls
36 lines (32 loc) · 746 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
const fill2DArray = (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() * 10 + 1);
}
}
return arr;
};
const sum2DArray = (arr) => {
let sum = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
sum += arr[i][j];
}
}
return sum;
};
const max2DArray = (arr) => {
let max = arr[0][0];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
if (max < arr[i][j]) {
max = arr[i][j];
}
}
}
return max;
};
let tomb = [[0, 0], [0, 0], [0, 0]];
console.log(fill2DArray(tomb));
console.log(sum2DArray(tomb));
console.log(max2DArray(tomb));