Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
darren102 wants to merge 1 commit into kodecocodes:master from darren102:master

Conversation

@darren102
Copy link

@darren102 darren102 commented Jan 28, 2016

Per discussion previously using isEmpty on the array instead of count

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.

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.

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.

Copy link
Member

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

Copy link

ghost commented Jan 29, 2016

In that case, what about ...

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

😄

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /