Skip to content

Instantly share code, notes, and snippets.

@renatocassino
Last active August 6, 2018 13:11
Show Gist options
  • Save renatocassino/e7622a1835ebc32a840e0cf61f48c5ed to your computer and use it in GitHub Desktop.
Save renatocassino/e7622a1835ebc32a840e0cf61f48c5ed to your computer and use it in GitHub Desktop.
2048-getEmptyBlocksNonFuncional.js
// Funcion non Functional
const getEmptyBlocksNonFunctional = (currentBoard) => {
const positions = []; // Variable with positions
for(let i = 0; i < currentBoard.length; i++) { // Iterate in columns
for(let j = 0; j < currentBoard[i].length; j++) { // Iterate in lines
if(currentBoard[i][j] === 0) {
positions.push([i, j]); // Append in pushes when 0
}
}
}
return positions; // return list os positions
};
const board = [[2, 2, 2, 2], [0, 4, 16, 16], [8, 8, 0, 32], [0, 0, 0, 64]];
console.log(getEmptyBlocksNonFunctional(board));
// Response: [ [ 1, 0 ], [ 2, 2 ], [ 3, 2 ], [ 3, 1 ], [ 3, 0 ] ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment