bug: abs returns 0 on an empty array - #1473
Conversation
There was a problem hiding this comment.
Not opposed to this as it seems to fix an edge case the author hadn't considered.
abs(null) will still be 0 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 this Abs 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 |
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.jsis allowed butuserprofile.js,Userprofile.js,user-Profile.js,userProfile.jsare notFixes: #{$ISSUE_NO}.