Solution

mail@pastecode.io avatar
unknown
javascript
3 years ago
622 B
1
Indexable
Never
    let rows = [];
    let columns = [];
    for(let row = 0; row < matrix.length; row++) {
        for(let column = 0; column < matrix[0].length; column++) {
            if (matrix[row][column] === 0) {
                rows.push(row);
                columns.push(column);
            }
        }
    }
    
    for(let column of columns) {
        for(let row = 0; row < matrix.length; row++) {
            matrix[row][column] = 0;
        }
    }
    
    for(let row of rows) {
        for(let column = 0; column < matrix[0].length; column++) {
            matrix[row][column] = 0;
        }
    }