The bitGraph.dfs() function returns an array of strings, with a format of 'i,j'. The matrix ends up with columns of ones and zeros. The goal is to have the indexes parsed from the strings of the matrix assigned to ones.
I checked the debugger and the line result[x][y] = 1 doesn't execute with each forEach iteration, but instead assigns a 1 to each element of the y column of the matrix at the end of the forEach.
const result = Array(N).fill(Array(M).fill(0));
Inside of a for loop:
bitGraph.dfs(`${N - 1},${j}`, visited)
.forEach(node => {
const [x, y] = node.split(',')
.map(index => Number(index));
result[x][y] = 1;
});
Example:
returned array: ['5,0', '4,0', '1,5', '1,4', '1,3']
result: [
[ 1, 0, 0, 1, 1, 1 ],
[ 1, 0, 0, 1, 1, 1 ],
[ 1, 0, 0, 1, 1, 1 ],
[ 1, 0, 0, 1, 1, 1 ],
[ 1, 0, 0, 1, 1, 1 ],
[ 1, 0, 0, 1, 1, 1 ]
]