File tree 3 files changed +6
-6
lines changed
3 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 1
1
//: Playground - noun: a place where people can play
2
2
3
- func linearSearch< T: Equatable > ( array: [ T ] , _ object: T ) -> Int ? {
4
- for (index, obj) in array. enumerate ( ) where obj == object {
3
+ func linearSearch< T: Equatable > ( _ array: [ T ] , _ object: T ) -> Int ? {
4
+ for (index, obj) in array. enumerated ( ) where obj == object {
5
5
return index
6
6
}
7
7
return nil
Original file line number Diff line number Diff line change 1
- func linearSearch< T: Equatable > ( array: [ T ] , _ object: T ) -> Int ? {
2
- for (index, obj) in array. enumerate ( ) where obj == object {
1
+ func linearSearch< T: Equatable > ( _ array: [ T ] , _ object: T ) -> Int ? {
2
+ for (index, obj) in array. enumerated ( ) where obj == object {
3
3
return index
4
4
}
5
5
return nil
Original file line number Diff line number Diff line change @@ -17,8 +17,8 @@ We compare the number `2` from the array to our number `2` and notice they are e
17
17
Here is a simple implementation of linear search in Swift:
18
18
19
19
``` swift
20
- func linearSearch <T : Equatable >(array : [T], _ object : T) -> Int ? {
21
- for (index, obj) in array.enumerate () where obj == object {
20
+ func linearSearch <T : Equatable >(_ array : [T], _ object : T) -> Int ? {
21
+ for (index, obj) in array.enumerated () where obj == object {
22
22
return index
23
23
}
24
24
return nil
You can’t perform that action at this time.
0 commit comments