Workshop › Pool › Step 19 of 33
A ball drops when its centre comes within POCKET_R of a pocket's centre. After every step we keep only the balls that
did not drop. Removing items while looping over the same array is a classic bug, so we build a new array with filter.
```js
function pocketed(b) {
return POCKETS.some(([px, py]) => Math.hypot(b.x - px, b.y - py) < POCKET_R)
}
balls = balls.filter((b) => !pocketed(b))
```some is true if the function is true for at least one pocket; [px, py] takes each pair apart in the parameter.filter makes a new array with only the items for which the function returns true: the balls not pocketed.collide, leave an empty line and write pocketed.step, under the pair loop line, write the filter line.Skills: Collision detection, Arrays and objects