Created
May 9, 2017 17:00
-
-
Save 0xch4z/eda45256a81bce61bc217ace9c38fbbc to your computer and use it in GitHub Desktop.
Swift 3 Linear Search Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func linearSearch<T:Equatable>(onArray array: Array<T>, forItem item: T) -> Int { | |
| for (index, i) in array.enumerated() where i == item { | |
| return index | |
| } | |
| return -1 | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment