This repository was archived by the owner on Nov 30, 2018. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This can be shorter via,
return unless value?.lng and value?.latThere 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.
@nmccready, nice! isn't as readable though. plus it checks for the existence of
valuetwice. to clarify:original code:
return if
valueis undefinedreturn if
valuedoesn't have alngor it doesn't have altdmy code:
return unless there is a
valuedefined withlngandltdyour code:
return unless
valueis defined and has alngandvalueis defined and has alatwhat do u say?
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 wouldn't say it is less readable, if your used to coffee this is a goto staple for me know. It eliminates tons of redundant code.
Also
unlessI normally use only if there is one variable to check for truthyness but your case works cause your using a bunch of ands. Basically unless has unexpected behavior at times where it really meansif !(value and value.lng and value.lat).Anyway this one liner is not worth arguing about.
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.
Actually this would have been best
return unless value?.lng and value.latthen one check for existence and it satisfies me and u.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.
good point, @nmccready ! :)