Skip to content

Instantly share code, notes, and snippets.

@rndD
Created April 19, 2016 22:38
Show Gist options
  • Save rndD/7cff1ca04d972ee8be33dab350239d08 to your computer and use it in GitHub Desktop.
Save rndD/7cff1ca04d972ee8be33dab350239d08 to your computer and use it in GitHub Desktop.
findCellsInRadius
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