function outerVolume(coords) {
const vol = toVolume(coords);
const outerVol = toVolume(coords, 1);
const toStr = ([x, y, z]) => x + "," + y + "," + z;
const [todo, visited] = [[[0, 0, 0]], new Set()];
while (todo.length > 0) {
const [x, y, z] = todo.shift();
const pStr = toStr([x, y, z]);
if (!visited.has(pStr)) {
visited.add(pStr);
if (vol[x][y][z] === 0) {
outerVol[x][y][z] = 0;
neighbours([x, y, z], vol).forEach(([nx, ny, nz]) => {
if (!visited.has(toStr([nx, ny, nz]))) {
todo.push([nx, ny, nz]);
}
});
}
}
}
return outerVol;
}