-
Notifications
You must be signed in to change notification settings - Fork 375
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
Always return +-1 or 0 in naturalCmp #324
Conversation
43749ac
to
6352c77
Compare
This looks good to me. |
Most likely true, I only noticed this issue because it was breaking several of my unit tests for an alternate compare method which delegates to |
I will test it more tomorrow and merge it then. |
Hmm... it looks like it's not uncommon to return something else than 1, 0 and -1 from function compareNumbers(a, b) {
return a - b;
} or http://stackoverflow.com/questions/17382091/javascript-sort-comparator-function I don't think the current implementation is a bug and after rethinking it I would rather not merge this PR and risk breaking someone else's code. I would recommend you to use Math.sign or a polyfill in your code if it is crucial to you to return 1,0,-1. return Math.sign(str.naturalCmp(this.prerelease.join("."), other.prerelease.join("."))); |
I'd say if not a bug its at least inconsistent. I'm on my phone so I'm not If (compare(a,b) == 1) Would be more likely than someone doing if (Compare(a,b) > 556) Especially as I haven't seen this behavior reported before. I'm under the Also the other commits correct some slightly off logic
|
Yes you may have a point with that. And I like the "of topic" changes and the tests. Thanks for the PR. |
Always return +-1 or 0 in naturalCmp
Fixes #323