Skip to content

Commit e390f59

Browse files
committed
Linear Search updated to Swift 4
1 parent 0e0ae64 commit e390f59

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Linear Search/LinearSearch.playground/Contents.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
//: Playground - noun: a place where people can play
22

3+
// last checked with Xcode 4.0b4
4+
#if swift(>=4.0)
5+
print("Hello, Swift 4!")
6+
#endif
7+
38
func linearSearch<T: Equatable>(_ array: [T], _ object: T) -> Int? {
4-
for (index, obj) in array.enumerated() where obj == object {
5-
return index
6-
}
7-
return nil
9+
for (index, obj) in array.enumerated() where obj == object {
10+
return index
11+
}
12+
return nil
813
}
914

1015
let array = [5, 2, 4, 7]

0 commit comments

Comments
 (0)