-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
74 lines (61 loc) · 1.97 KB
/
script.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
70
71
72
73
74
var binArray = [[1,1,0],[0,1,0,1,0,6],[1,1,1,0,1]];
var row = 0;
for (let i = 0; i < binArray.length; i++) {
if(binArray[i].length >= row)
row = binArray[i].length;
}
var col = binArray.length;
var a = searchMaxSum(binArray);
var b = foo(binArray);
function searchMaxSum(array) {
var sumOfRow = [0], maxRow = [0];
for (let i = 0; i < array.length; i++) {
maxRow[i] = array[i].reduce(function(sum, current) {
return sum + current;
}, 0);
sumOfRow[i] = maxRow[i];
}
return sumOfRow;
}
function foo(array){
var maxColumn=new Array(col);
for (var k = 0; k < binArray.length; k++) {
maxColumn[k]=new Array(row);
maxColumn[k]=0;
}
var sumOfColumn = [0];
for (var i = 0; i < array.length; i++) {
for (var j = 0; j < array.length; j++) {
if(array[j][i] == 0)
continue;
maxColumn[i] = +maxColumn[i] + array[j][i];
}
sumOfColumn[i] = maxColumn[i];
}
return sumOfColumn;
}
console.log(2);
// for (let index = 0; index < sumOfRow.length; index++) {
// console.log(`sumOfRow${index}`, sumOfRow[index]);
// }
// for (let index = 0; index < sumOfColumn.length; index++) {
// console.log(`sumOfColumn${index}`, sumOfColumn[index]);
// }
// array[j].reduce(function(sum, current) {
// return sum + current;
// }, 0);
// sumOfColumn[j] = maxColumn[j];
// j+=2;
// if(maxRow[i] >= sumOfRow[i])
// sumOfRow[i] = maxRow[i];
// a.reduce(function(a, b) { return a + b; }, 0);
// for (let i = 0; i < array.length; i++) {
// sumOfRow[i] = sumOfRow[i] + array[i];
// sumOfColumn[i] = new Array(array[i].length);
// for (let j = 0; j < array.length; j++) {
// if(array[j] != NaN)
// sumOfColumn[i][j] += array[i][j];
// else
// break;
// }
// }