Skip to content

Commit

Permalink
Fix Removing Duplicates Order
Browse files Browse the repository at this point in the history
  • Loading branch information
JannThomas committed Aug 31, 2023
1 parent 3ac6818 commit 543b2d8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/SchafKit/Extensions/Collections/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,17 @@ public extension Array where Element: Hashable {

/// Returns an array with the duplicates removed.
func removingDuplicates() -> [Element] {
Array(Dictionary<Element, [Element]>(grouping: self, by: { $0 as Element }).keys)
var newArray = Self()
var checkingDict: [Element: Bool] = [:]

for element in self {
if checkingDict[element] != true {
newArray.append(element)
checkingDict[element] = true
}
}

return newArray
}

/// Removes duplicates in an array.
Expand Down

0 comments on commit 543b2d8

Please sign in to comment.