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
Simplified code #2
Conversation
improved performance as a side effect
why not simply |
@fr33kvanderwand Because |
Nice, passes all tests. Can you explain how this works exactly? Thanks 👍 |
Going to pull this in, but please do provide me with an explanation. I would love to add it in as comments. Thanks! |
This function returns false for Number.MAX_SAFE_INTEGER |
@fearphage, thoughts on #5 ? EDIT: #6 |
It also adheres to your lint rules.
I've read that Math.pow(2, 53) === Math.pow(2, 53) + 1 // returns true You could add |
Added a bunch of broken test cases here: https://github.com/tjmehta/is-positive-integer/pull/7/files |
Looks like it breaks for more than just the "MAX" cases |
Not sure if anyone cares, but from looking at the code the behavior was changed with regards to what happens if you pass non numeric objects in that define valueOf. |
@mitsuhiko, which non numeric objects functionality changed? Is there a missing test case: https://github.com/tjmehta/is-positive-integer/blob/master/test/test.js? |
@tjmehta for instance an object like this: let foo = {
valueOf: function() { return 42; }
}; In the old code this was not considered an integer, in this code I assume it will be one due to the coercion. I did not actually test any of this. Just saw the PR pop up on twitter. |
Also pretty sure passing in |
Why not?
|
@twistor, |
@mitsuhiko, just tested, both are false. added test cases: https://github.com/tjmehta/is-positive-integer/pull/7/files |
@tjmehta indeed. the I have nothing further to add :) |
Used the native functionality instead of external modules. This greatly improved performance as a side effect:
It's roughly 25 times faster now.
Source: https://gist.github.com/fearphage/3d50dd7a454a37e35392