Skip to content

Instantly share code, notes, and snippets.

@AsifITk
Created September 8, 2022 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsifITk/71e99d0148c27e7da5a08f807d409727 to your computer and use it in GitHub Desktop.
Save AsifITk/71e99d0148c27e7da5a08f807d409727 to your computer and use it in GitHub Desktop.
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