Skip to content

Support null and undefined values #7

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

Merged
merged 4 commits into from
Sep 11, 2017
Merged

Support null and undefined values #7

merged 4 commits into from
Sep 11, 2017

Conversation

doowb
Copy link
Collaborator

@doowb doowb commented Sep 10, 2017

This PR fixes #3.

I'm opening the PR to get feedback before publishing. Since the built-in Array.prototype.sort function will push null and undefined values to the end of the array, I implemented this in a similar fashion.

My first thought was that this could be implemented with a custom compare function, but the get-object functionality would have to be added to that custom compare function too.

index.js Outdated
return -1;
} else {
return a < b ? -1 : (a > b ? 1 : 0);
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

damn, I messed around with this and had similar logic to what you just did, but yours is cleaner. At least this validates that it will take something like this to fix the issue, I was wondering if there was an easier way.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I went through a bunch of different implementations and I think this uses the least amount of checks. And since > and < always return false when null is involved, this needs to be done.

@jonschlinkert
Copy link
Owner

I agree that this needs to be done here. thanks!

@doowb doowb merged commit 0268fdc into master Sep 11, 2017
@doowb doowb deleted the null-values branch September 11, 2017 18:16
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.

comparison to null strings
2 participants