MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / search

Function search

matrix/number-of-islands.js:17–29  ·  view source on GitHub ↗
(grid, row, col)

Source from the content-addressed store, hash-verified

15}
16
17function search(grid, row, col) {
18 const stack = [[row, col]];
19
20 while (stack.length > 0) {
21 const currentPosition = stack.pop();
22 const [currentRow, currentCol] = currentPosition;
23 grid[currentRow][currentCol] = "0";
24 const neighbors = getNeighbors(grid, currentRow, currentCol);
25 for (const neighbor of neighbors) {
26 stack.push(neighbor);
27 }
28 }
29}
30
31function getNeighbors(grid, row, col) {
32 const neighbors = [];

Callers 1

numIslandsFunction · 0.85

Calls 3

getNeighborsFunction · 0.70
popMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected