Skip to content

Conversation

@dhimansachit
Copy link

image

Tests passing

@josdejong
Copy link
Owner

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.

@dhimansachit
Copy link
Author

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?

Copy link
Owner

@josdejong josdejong left a 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?

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++) {
Copy link
Owner

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])
}

Copy link
Author

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().

Copy link
Contributor

@AnslemHack AnslemHack Dec 2, 2025

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

Copy link
Owner

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?

Copy link
Author

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.

@josdejong
Copy link
Owner

I see that some unit tests are failing now, I guess those are the existing unit tests that now return a differing order.

@josdejong josdejong changed the title [Issue-3602] - fixing setDistinct order [BREAKING] Fix #3602 let setDistinct keep the original order Nov 28, 2025
@josdejong josdejong changed the base branch from develop to v16 November 28, 2025 13:19
@josdejong josdejong added this to the v16 milestone Nov 28, 2025
@dhimansachit
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants