Remove array extensions
This commit is contained in:
parent
556078e7d0
commit
ac7820bdd2
|
|
@ -8,6 +8,7 @@
|
|||
- **Remove**: String+Extensions
|
||||
- **Remove**: UICollectionView+CellRegistration
|
||||
- **Remove**: UIStoryboard+InstantiateViewController
|
||||
- **Remove**: `Array` extensions with `Set Algebra`
|
||||
|
||||
## 0.5.18
|
||||
- **Fix**: EmptyCell first appearance setup fix
|
||||
|
|
|
|||
|
|
@ -20,52 +20,10 @@
|
|||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
public extension Array where Element: Equatable {
|
||||
|
||||
/// Union array with another arrays, without element duplication
|
||||
func union(values: [Array.Element]...) -> Array {
|
||||
var result = self
|
||||
|
||||
for array in values {
|
||||
for value in array {
|
||||
if !result.contains(value) {
|
||||
result.append(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/// Find common elements among arrays
|
||||
func intersection(values: [Array.Element]...) -> Array {
|
||||
var result = self
|
||||
var intersection = Array()
|
||||
|
||||
for (index, value) in values.enumerated() {
|
||||
if index > 0 {
|
||||
result = intersection
|
||||
intersection = Array()
|
||||
}
|
||||
|
||||
value.forEach { item in
|
||||
if result.contains(item) && !intersection.contains(item) {
|
||||
intersection.append(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return intersection
|
||||
}
|
||||
|
||||
/// Find unique elements in array compared to other arrays
|
||||
func subtract(values: [Array.Element]...) -> Array {
|
||||
let allValues = values.flatMap { $0 }
|
||||
return filter { !allValues.contains($0) }
|
||||
}
|
||||
public extension Array {
|
||||
|
||||
// Subscript for safe access to element by index
|
||||
subscript(safe index: Int) -> Element? {
|
||||
subscript(safe index: Index) -> Element? {
|
||||
return index < count ? self[index] : nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue