Created
July 8, 2020 18:37
-
-
Save kyleshevlin/9587252e1c54050aa4deb1d11319f339 to your computer and use it in GitHub Desktop.
recursiveReducer
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
// Part of my Othello code, no idea if this is the _best_ way to solve this, | |
// but it's part of my solution | |
// `grid` is in the parent scope how I write/use this function | |
function findPiecesToChange(acc, x, y, run, rise) { | |
const nextX = x + run | |
const nextY = y + rise | |
const cell = grid[nextY] && grid[nextY][nextX] | |
if (!cell) { | |
return null | |
} | |
if (cell === turn) { | |
return acc | |
} | |
return findPiecesToChange( | |
[...acc, { x: nextX, y: nextY }], | |
nextX, | |
nextY, | |
run, | |
rise | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment