-
Couldn't load subscription status.
- Fork 5k
Using isEmpty instead of count for the array pop method #8
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
That guard is really confusing. It reads like "if array is not 'not empty' then return nil. isEmtpy is better than count == 1 but I think guard should be reserved for failing to bind an optional value at the beginning of the function.
I like the use of isEmpty, but agree that guard makes it more confusing than it needs to be. So I'll close this PR and make those changes.
ghost
commented
Jan 29, 2016
Why not simply...
if array.isEmpty { return nil } return array.removeLast()
I don't think an else is necessary here.
The else is not strictly necessary, but in my opinion it does clarify the flow of what's going on.
ghost
commented
Jan 29, 2016
In that case, what about ...
return array.isEmpty ? nil : array.removeLast()
😄
Perfectly fine, but since the goal of this project is to teach algorithms I'd prefer to stick with an simple if-else since everyone understands that.
Per discussion previously using
isEmptyon the array instead ofcount