Last active
August 6, 2018 13:11
-
-
Save renatocassino/e7622a1835ebc32a840e0cf61f48c5ed to your computer and use it in GitHub Desktop.
2048-getEmptyBlocksNonFuncional.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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