Skip to content

Commit 61c9376

Browse files
authored
Merge pull request #566 from shabirjan/LinearSearch-Swift4
Linear search Swift4
2 parents 9f85804 + b7b6130 commit 61c9376

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

Linear Search/LinearSearch.playground/Contents.swift

+9-4
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]

Linear Search/LinearSearch.playground/timeline.xctimeline

-6
This file was deleted.

0 commit comments

Comments
 (0)