1
var findBall = function (grid) {5
for (let start = 0; start < n; start++) {6
// Iterate through the different starting conditions8
for (let i = 0; i < m; i++) {9
// Then iterate downward from grid[i][j]10
let dir = grid[i][j]; // Compare the direction of the current cell to the direction11
if (dir === grid[i][j + dir])12
j += dir; // of the cell on the slant side and move that way if matched13
else (i = m), (j = -1); // Otherwise jump to the loop's end and set j to the fail value15
ans[start] = j; // Update the answer17
return ans; // Return the completed answer