-
-
Save AsifITk/71e99d0148c27e7da5a08f807d409727 to your computer and use it in GitHub Desktop.
This file contains 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
let whereTheBall = (grid) => { | |
let tempArr = []; | |
for (let i = 0; i < grid[0].length; i++) { | |
let ball = i; | |
tempArr.push(-1); | |
for (let j = 0; j < grid.length; j++) { | |
if (grid[j][ball] === 1 && grid[j][ball + 1] === 1) { ball = ball + 1; } | |
else if (grid[j][ball] === -1 && grid[j][ball - 1] === -1) { ball = ball - 1; } | |
else break; | |
if (j === grid.length - 1) { | |
tempArr.pop(); | |
tempArr.push(ball); | |
}; | |
} | |
} | |
return tempArr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment