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

math.median(A) mutates A #309

Closed
mrtns opened this Issue Mar 26, 2015 · 5 comments

Comments

Projects
None yet
3 participants
@mrtns

mrtns commented Mar 26, 2015

Given an array a:

> var a = [3,2,1];

> a
< [3, 2, 1]

When mean is called:

> mathjs.mean(a);
< 2

the sort order of a is preserved:

> a
< [3, 2, 1]

However, when median is called:

> mathjs.median(a);
< 2

the sort order of a is lost. a is mutated, and is now sorted ascending:

> a
< [1, 2, 3]

It this expected behaviour? If not, I can provide a PR with failing test. Thanks!

@josdejong

This comment has been minimized.

Owner

josdejong commented Mar 26, 2015

Thanks, non of the functions of math.js should mutate the inputs, this is not intended behavior.

If you can provide a fix for this would be great, thanks.

@josdejong

This comment has been minimized.

Owner

josdejong commented Mar 26, 2015

And preferably an extra unit test to prevent any regression in the future...

FSMaxB added a commit that referenced this issue Apr 25, 2015

functions/statistics/median: test for issue (#309)
This is a test to check that median doesn't mutate it's input
@FSMaxB

This comment has been minimized.

Collaborator

FSMaxB commented Apr 25, 2015

This bug is fixed in the develop branch.

@josdejong

This comment has been minimized.

Owner

josdejong commented Apr 26, 2015

Thanks Max. I've updated the HISTORY.md file accordingly

@josdejong

This comment has been minimized.

Owner

josdejong commented May 31, 2015

This is now fixed in v1.7.0

@josdejong josdejong closed this May 31, 2015

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