Skip to content

Instantly share code, notes, and snippets.

@RatoX
Last active May 17, 2018 01:22
Show Gist options
  • Save RatoX/23237bcd1b1eb33e04d5988e5319716c to your computer and use it in GitHub Desktop.
Save RatoX/23237bcd1b1eb33e04d5988e5319716c to your computer and use it in GitHub Desktop.
Inundação
const matrix = [
[ 0,0,1,0,1],
[ 1,1,0,1,1],
[ 0,1,0,1,0 ],
[ 0,1,1,1,1 ],
[ 1,0,1,0,1 ],
]
function checkZero (index_x, index_y, check) {
const temp = matrix[index_x] || []
if (temp[index_y] === 0) {
matrix[index_x][index_y] = check
checkNeibors(index_x, index_y, check)
}
}
function checkNeibors(index_row, index_column, randomString) {
checkZero(index_row - 1, index_column + 1, randomString)
checkZero(index_row, index_column + 1, randomString)
checkZero(index_row + 1, index_column + 1, randomString)
checkZero(index_row + 1, index_column, randomString)
checkZero(index_row + 1, index_column - 1, randomString)
}
const LETTERS = ['A', 'E', 'I', 'O', 'U']
matrix.forEach((x) => {
console.log(x)
})
matrix.forEach((row, index_row) => {
row.forEach((element, index_column) => {
if( element === 0 ) {
const check = LETTERS.reverse().pop()
matrix[index_row][index_column] = check
checkNeibors(index_row, index_column, check)
}
})
})
console.log('------------')
matrix.forEach((x) => {
console.log(x)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment