Hello Xavier! Thank you for your comment. You’re absolutely right that the second way (using Array#compact) is better Ruby code. I originally had it implemented that way, but I worried that the Array#compact idiom would require more explanation for non-Rubyists. The first version is more verbose, but I think it explains the intention better, and is more easily portable to other languages.
Ultimately, this means that there will be more idiomatic ways to implement many of these methods in Ruby, but it’s a trade-off.
I’ll consider this some more, but ultimately I don’t want non-Rubyists to be discouraged from reading this book—the algorithms are really at the core of it.
Thanks again! I really appreciate your feedback on this issue. It’s been a tricky one for me to find a balance here.