Sri searches the train with find, findIndex, filter, some and every, each call the engine made logged, then a binary search that halves the train: what if the…
The key idea
Same question: pick the method by the shape of answer you need
Try it in this playground
find against filter Run find until it stops, then filter: count the wagons looked at.
Nothing matches Use n => n > 40: find gives undefined, filter gives [] that is still truthy.
Search by halving cariBiner on the sorted ticket train: three looks for eight wagons.
Halving on a shuffled train cariBiner on a train that is not sorted: x is there, but it gives -1.