halfStablePartition을 한다.
삭제할 첫번째 원소를 찾는다.
이후 루프를 돌면서 다음 삭제할 원소를 찾는다.
extension MutableColleciton {
mutating func halfStablePartition(isSuffixElement: (Element) -> Bool) -> Index {
guard var i = firstIndex(where: isSuffixElement) else { return endIndex }
var j = index(after: i)
while j != endIndex {
if !isSuffixElement(self[j]) { swapAt(i, j); formIndex(after: &j) }
formIndex(after: &j)
}
return i
}
}
뒷부분을 자른다.