CS fundamentals and algorithms
Stable sorting
You take a contacts array already sorted by name and re-sort it with contacts.sort { $0.isFavorite && !$1.isFavorite }, and the names inside the favorites group stay in order. Why is that guaranteed?
Pick one