Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

darren102
Copy link

Per discussion previously using isEmpty on the array instead of count

@kevinrandrup
Copy link
Contributor

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.

@hollance
Copy link
Member

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
Copy link

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.

@hollance hollance closed this Jan 29, 2016
@hollance hollance reopened this Jan 29, 2016
@hollance
Copy link
Member

The else is not strictly necessary, but in my opinion it does clarify the flow of what's going on.

@ghost
Copy link

ghost commented Jan 29, 2016

In that case, what about ...

return array.isEmpty ? nil : array.removeLast()

😄

@hollance
Copy link
Member

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.

@hollance hollance closed this Jan 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants