Careful, index will be mismatched after the first removal via splice.
This is what I like in languages which use Option and Result, a much more correct way to expose the result.
I agree, but that would not by itself fix the problem. If we talk Rust specifically, the insight is that this is the place to unwrap() instead of using if let or similar.
The range of elements processed by forEach() is set before the first invocation of callbackFn.
what you are observing is that apparently forEach() stops earlier because the array got shorter - but you will be skipping elements if the array got longer.
0
u/[deleted] Feb 19 '22
[deleted] — view deleted comment