Answer the question
In order to leave comments, you need to log in
How to convert the elements of a column in a two-dimensional array, for example, to '0' or remove if the sum of the column is less than zero?
Help, please, solve the problem. In a two-dimensional array, remove columns where the sum of the column elements < 0.
The array must be 5 by 5, filled with random numbers.
I found the sums, but I don’t understand how to delete a column or change the elements in it (((
let A = new Array(n);
for (let row=0; row<A.length; row++){
A[row] = new Array(m)
for (let col=0; col<A[row].length; col++) {
A[row][col] = Math.floor(Math.random()*10) -10;
console.log(A[row][col]);
document.write(A[row][col] + ' ');
}
document.write('<br>');
}
//Сумма колонок
SumCol =[];
for (let col=0; col<A.length; col++){
Sum = 0;
for (let row=0; row<A[col].length; row++) {
Sum += A[row][col];
}
if (Sum < 0) {
for (let i=0; i<A.length; i++) {
A[row][col] ='*';
}
console.log(A);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question