-
-
Save rndD/7cff1ca04d972ee8be33dab350239d08 to your computer and use it in GitHub Desktop.
findCellsInRadius
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
const findCellsInRadius = (w, h, center, radius) => { | |
let cellsInRadius = []; | |
let [centerX, centerY] = center; | |
_.range(w).forEach((x) => { | |
let rangeX = Math.abs(centerX - x); | |
(rangeX < radius) && _.range(h).forEach((y) => { | |
let rangeY = Math.abs(centerY - y); | |
(rangeY + rangeX) <= radius && cellsInRadius.push([x,y]); | |
}); | |
}); | |
return cellsInRadius; | |
}; | |
console.log(findCellsInRadius(10,10, [3,3], 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment