-
Notifications
You must be signed in to change notification settings - Fork 5k
switch from local removeFirst copy to iteration for pairing #452
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
Conversation
we don't need a mutable copy of `array` to alter it, instead we can just drop the first element
we don't need to alter a mutable copy of `array`, instead we can just drop the first element.
We don't need to alter a local copy of `array` to generate each pair, instead use stride(from:to:by). In my simple [tests](https://gist.github.com/TheIronBorn/cc0507b36fddad291aa34674eb52ad8f), this can be up to an order of magnitude faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the polish you gave to this. I left a suggestion that applies to the many of the functions. Let me know what you think.
Select Minimum Maximum/Maximum.swift
Outdated
@@ -3,13 +3,12 @@ | |||
*/ | |||
|
|||
func maximum<T: Comparable>(_ array: [T]) -> T? { | |||
var array = array | |||
guard !array.isEmpty else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're force unwrapping array.first
due to this guard
statement's guarantee, let's merge the two:
// guards against the empty array and also extracts the first element of the array
guard let maximum = array.first else { return nil }
Oh yeah that's fine. I'll implement in a minute. |
Looks great! Cheers |
Checklist
Description