4 ms·
> Can you tweak your function to stop filling the first time a zero is encountered? That's a simple one-line change with the for loop, but a puzzle for the func
by unrealhoang 6y ago
> Can you tweak your function to stop filling the first time a zero is encountered? That's a simple one-line change with the for loop, but a puzzle for the functional iteration.
In Rust:
a.iter_mut().take_while(|i| *i == 0).for_each(|i| *i = 0)
And it's as fast as hand-written for loop.