-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[BREAKING] Fix #3602 let setDistinct keep the original order #3603
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
base: v16
Are you sure you want to change the base?
Conversation
|
Thanks @dhimansachit for working out a solution with tests! Can you please undo the formatting changes in the file? It's hard to see what actually changed. |
Hi @josdejong reverted the formatting changes. Can you please review once now? |
josdejong
left a comment
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.
Thanks for the update @dhimansachit ! This looks good 👌
I made one inline remark, can you have a look at that?
src/function/set/setDistinct.js
Outdated
| for (let i = 1; i < b.length; i++) { | ||
| if (compareNatural(b[i], b[i - 1]) !== 0) { | ||
| let found = false | ||
| for (let j = 0; j < result.length; j++) { |
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.
How about using the array find method or some or every? For example:
if (result.every(item => compareNatural(b[i], item) !== 0)) {
result.push(b[i])
}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.
Sure. Updated the logic to use some().
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.
Hi @dhimansachit, thanks for sending this PR I really appreciate the effort you’re putting into improving mathjs. however For readability and maintainability, could you extract the inline function into a small helper with a descriptive name? That way the intent is clearer at a glance. For example:
const containsItem = (arr, value) =>
arr.some(item => compareNatural(value, item) === 0);
if (!containsItem(result, b[i])) {
result.push(b[i]);
} @josdejong if you don't mind
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.
Thanks for thinking along Anslem.
I'm OK with both inline or helper function. Do you have any preference @dhimansachit?
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.
I think it's better that it's inline as the function is not used anywhere else. But I'm fine with the other approach as well. Please let me know if you want me to update the logic to contain a function or const for storing the found elements.
|
I see that some unit tests are failing now, I guess those are the existing unit tests that now return a differing order. |
Sorry, my bad. Didn't update the previous test. Updated now in the latest commit. |
Tests passing