Wulan’s parcel weights on train #1: find walks from the locomotive, findLast from the tail, each stopping at its first yes, and what happens to the real train…
The key idea
findLast searches from the back without turning anything round
Common mistakes
Expecting a different result from find when only one matches When only one wagon matches, find and findLast stop at the same wagon. The difference shows only with two or more.
Try it in this playground
Run find, then findLast The same predicate, opposite walks: see which wagon each one stops at.
Try the old arr.reverse().find() The result is right, but look at train #1 afterwards.
Try the index from a reversed copy Sri needs the wagon number on arr, not on the copy.
Search for something that is not there Raise k until nothing matches: undefined for a value, -1 for an index.