Introduce EraseLastKElementsIf to simplify the node eviction code
Summary:
There is a redundant pattern in the SelectNodeToEvict algorithm, which can be fatorized to make the code easier to follow.
There is no change in behavior.
Ref T1634.
Test Plan:
ninja all check-all
Reviewers: #bitcoin_abc, deadalnix
Reviewed By: #bitcoin_abc, deadalnix
Maniphest Tasks: T1634
Differential Revision: https://reviews.bitcoinabc.org/D9863