FloodFill

Home page

Flood fill, also called seed fill, is an algorithm that determines the area connected to a given node in a multi-demensial array.

Try out muy solution below.
Answer:
Recursion:
let count = 0;
let visited = {};
numOfOnesRecursive = (list, x, y) => {
    if (!list[x] || !list[x][y])
        return;
    if (list[x][y] === 0 || (typeof visited[x + ',' + y] !== 'undefined' && visited[x + ',' + y]))
        return;
    count++;
    visited[x + ',' + y] = true;
    numOfOnesRecursive(list, x, y-1);
    numOfOnesRecursive(list, x, y+1);
    numOfOnesRecursive(list, x-1, y);
    numOfOnesRecursive(list, x+1, y);
    return count;
}