We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c4571a9 commit 19d8965Copy full SHA for 19d8965
Sources/SwifterSwift/SwiftStdlib/ArrayExtensions.swift
@@ -58,7 +58,7 @@ public extension Array {
58
/// - keyPath: keyPath indicating the property that the array should be sorted by
59
/// - Returns: sorted array.
60
func sorted<T: Hashable>(like otherArray: [T], keyPath: KeyPath<Element, T>) -> [Element] {
61
- let dict = otherArray.enumerated().reduce(into: [:]) { $0[$1.element] = $1.offset }
+ let dict = Dictionary(uniqueKeysWithValues: otherArray.enumerated().map { ($1, $0) })
62
return sorted {
63
guard let thisIndex = dict[$0[keyPath: keyPath]] else { return false }
64
guard let otherIndex = dict[$1[keyPath: keyPath]] else { return true }
0 commit comments