Skip to content

Instantly share code, notes, and snippets.

@0xch4z
Created May 9, 2017 17:00
Show Gist options
  • Select an option

  • Save 0xch4z/eda45256a81bce61bc217ace9c38fbbc to your computer and use it in GitHub Desktop.

Select an option

Save 0xch4z/eda45256a81bce61bc217ace9c38fbbc to your computer and use it in GitHub Desktop.
Swift 3 Linear Search Algorithm
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