Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.7k
bug: abs returns 0 on an empty array#1473
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
bug: abs returns 0 on an empty array#1473
Uh oh!
There was an error while loading.Please reload this page.
Conversation
appgurueu left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Not opposed to this as it seems to fix an edge case the author hadn't considered.
abs(null)
will still be0
due to the coercion of+
. Types should probably be checked before coercing, otherwise it makes the most sense to accept JS coercion rules.
Frankly I think thisAbs
function is a mess without algorithmic value though. I think it would probably be best to remove it.
abs(null) will still be caught by the object check since |
appgurueu commentedOct 8, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
That's true, I missed this. As said, I approve this PR, it makes the function be closer to what the interface was supposed to be. But that interface doesn't make a whole lot of sense. It should coerce some types, but not others? The interface of this function is inconsistent both with JavaScript coercion and with sane strict behavior. The function also is algorithmically trivial, so we should probably weed it out sooner or later. In the future, we should either have (1) strict type checks (in this case: only allow a number) or (2) preferably, no overly defensive type checks, as is idiomatic in JavaScript, and simply assuming the user knows what (not) to do (which of course needs to be documented properly). |
Describe your change:
Checklist:
Example:
UserProfile.js
is allowed butuserprofile.js
,Userprofile.js
,user-Profile.js
,userProfile.js
are notFixes: #{$ISSUE_NO}
.