Skip to content

math.median(A) mutates A  #309

@mrtns

Description

@mrtns

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions