I have JavaScript array with numbers 0 and 1 and I need to make a sum of all numbers in same row and column (if I imagine my array in two dimensions). I want to create second array with sums for every single value in first array.
2D array visualization for first item (X-Y table of values):
1,1,1,1,1
1,1,1,1,1
1,1,1,1,1
1,1,1,1,1
1,1,1,1,1
(Sum: 8 for value at index 0;0 (with value itself excluded))
Real array I have:
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
(Sum: 8 for value at index 0)
2D array visualization for second item:
1,1,1,1,1
1,1,1,1,1
1,1,1,1,1
1,1,1,1,1
1,1,1,1,1
(Sum: 8 for value at index 1;0)
This way I need to loop through whole array.
2D array visualization for second item with zero separator:
1,1,1,1,1
1,1,1,1,1
1,0,1,1,1
1,1,1,1,1
1,1,1,1,1
(Sum: 5 for value at index 1;0)
Values after zero I don't want to count in.
For previous table the result table should be like...
8,5,8,8,8
8,5,8,8,8
4,x,6,6,6
8,5,8,8,8
8,5,8,8,8
Thank you very much for your help!
Array 0 [ 1, 1, 0, 1 ]Array 1 [ 1, 1, 1, 1 ]Array 2 [ 1, 1, 1, 1 ]Array 3 [ 1, 1, 0, 1 ]But I can't figure out how to sum the value I want.