Mr. Wiryo walks train #1 replaying every callback call the engine made: map builds a new train, filter couples only the wagons that pass, reduce carries the…
The key idea
map, filter and reduce do not change the original array
Try it in this playground
Run map to the end A new train as long as train #1 fills wagon by wagon: one in, one out.
Run filter to the end Only the wagons whose callback says yes join the new train.
Follow reduce step by step Watch the total on the scale change at every wagon. Try it with no start value: the first call moves to wagon 1.
Compare find and filter find stops at the first and returns one value; filter checks them all and returns a train.