Null out rows and columns of null cells in place
A greenhouse dashboard shows a grid of sensor readings: one row per shelf, one column per hour. A reading of null means a sensor glitch, and when a sensor glitches the whole shelf and the whole hour become untrustworthy. Before drawing the heat map, the dashboard quarantines them.
Implement quarantineGrid(grid). For every cell that is null when the function is called, set every cell in its row and every cell in its column to null. Modify grid in place and return the number of cells that changed to null.
quarantineGrid(grid) // => number
grid is a rectangular array of rows. Every cell is a number or null.null at the start spread. A cell that becomes null during quarantine does not quarantine its own row and column.0 and NaN are readings, not glitches.null afterwards. Cells that were already null do not count.[]) or a grid of empty rows returns 0.const readings = [
[21, 22, 23, 22],
[20, null, 24, 23],
[19, 21, 22, 0],
];
quarantineGrid(readings); // => 5
// readings is now:
// [
// [21, null, 23, 22],
// [null, null, null, null],
// [19, null, 22, 0],
// ]
const twoGlitches = [
[null, 5, 6],
[7, 8, 9],
[1, 2, null],
];
quarantineGrid(twoGlitches); // => 6
// [
// [null, null, null],
// [null, 8, null],
// [null, null, null],
// ]
// The middle cell survives: its row and column had no glitch at the start.
quarantineGrid([[1, 2], [3, 4]]); // => 0, unchanged