Visited array to keep track of visited nodes in order to avoid infinite loops
let visited = new Array ( R ) ; for ( let i = 0 ; i < R ; i ++ ) { table [ i ] = new Array ( C ) ; visited [ i ] = new Array ( C ) ; }