Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I fixed it by slightly changing the if condition inside the forEach function to this: const middleDistance = robot.position - this.middle; and to establish minMiddleDistance: if (middleDistance > 0 && middleDistance < this.minMiddleDistance) Full code: repl.it/repls/ExternalFatalDemands
That was a concern I had as well... what I ended up doing was generate a new d1 at the very end of the loop (see above) and see if the new distance when added to the current position on the lane would surpass 1km. Hope this provides some clarification.