Skip to content

Replaces references to indexOf(_:) with index(of:). #696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Binary Search/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Goal: Quickly find an element in an array.

Let's say you have an array of numbers and you want to determine whether a specific number is in that array, and if so, at which index.

In most cases, Swift's `indexOf()` function is good enough for that:
In most cases, Swift's `Collection.index(of:)` function is good enough for that:

```swift
let numbers = [11, 59, 3, 2, 53, 17, 31, 7, 19, 67, 47, 13, 37, 61, 29, 43, 5, 41, 23]

numbers.indexOf(43) // returns 15
numbers.index(of: 43) // returns 15
```

The built-in `indexOf()` function performs a [linear search](../Linear%20Search/). In code that looks something like this:
The built-in `Collection.index(of:)` function performs a [linear search](../Linear%20Search/). In code that looks something like this:

```swift
func linearSearch<T: Equatable>(_ a: [T], _ key: T) -> Int? {
Expand Down