@@ -3,7 +3,7 @@ extension Collection where Element: Equatable {
3
3
/// Returns next index with unique value. Works only on sorted arrays.
4
4
///
5
5
/// - Parameter index: The current `Int` index.
6
- /// - Returns: The new `Int` index. Will return `nil` if new index happens to be the `endIndex` (out of bounds)
6
+ /// - Returns: The new index. Will return `nil` if new index happens to be the `endIndex` (out of bounds)
7
7
func uniqueIndex( after index: Index ) -> Index ? {
8
8
guard index < endIndex else { return nil }
9
9
var index = index
@@ -13,20 +13,16 @@ extension Collection where Element: Equatable {
13
13
formIndex ( after: & nextIndex)
14
14
}
15
15
16
- if nextIndex == endIndex {
17
- return nil
18
- } else {
19
- return nextIndex
20
- }
16
+ return nextIndex != endIndex ? nextIndex : nil
21
17
}
22
18
}
23
19
24
20
extension BidirectionalCollection where Element: Equatable {
25
21
26
22
/// Returns next index with unique value. Works only on sorted arrays.
27
23
///
28
- /// - Parameter index: The current `Int` index.
29
- /// - Returns: The new `Int` index. Will return `nil` if new index happens to come before the `startIndex` (out of bounds)
24
+ /// - Parameter index: The current index.
25
+ /// - Returns: The new index. Will return `nil` if new index happens to come before the `startIndex` (out of bounds)
30
26
func uniqueIndex( before index: Index ) -> Index ? {
31
27
return indices [ ..< index] . reversed ( ) . first { index -> Bool in
32
28
let nextIndex = self . index ( after: index)
@@ -36,7 +32,7 @@ extension BidirectionalCollection where Element: Equatable {
36
32
}
37
33
}
38
34
39
- func threeSum< T: BidirectionalCollection > ( _ collection: T , target: T . Element ) -> [ [ T . Element ] ] where T. Element: BinaryInteger & Comparable {
35
+ func threeSum< T: BidirectionalCollection > ( _ collection: T , target: T . Element ) -> [ [ T . Element ] ] where T. Element: Numeric & Comparable {
40
36
let sorted = collection. sorted ( )
41
37
var ret : [ [ T . Element ] ] = [ ]
42
38
0 commit comments