Median doesn't ever return in some cases containing NaN values, handing the process indefinitely
Hangs:
mathjs.median(NaN, NaN, NaN)mathjs.median(2, NaN, NaN)Returns NaN
mathjs.median(2, NaN)mathjs.median(NaN)I would expect all these cases to return NaN, or even something else but not to hang the javascript process.
Thanks for reporting this bug! We'll fix it asap.
@gnobre this issue should be solved now in [email protected]. Turns out there was an issue in sorting an array containing numbers including NaN: since both 2 > NaN and NaN > 2 returns false, the sorthing mechanism (inside the function partitionSelect) could get stuck in an infinite loop.
I've added tests for NaN in all statistics functions, see commit.
@harrysarson I was really happy (again) with our testing on travis: turns out assert.strictEqual(NaN, NaN) doesn't work property on older node.js versions (6 and 8), and maybe also not in browsers. :+1:
@josdejong thanks for resolving this so quick, this was a really tricky one indeed!
The new tests are nice aswell :+1: