Need to write a JS function compare(a,b) for numbers which return 1 when a > b, 0 when a == b, -1 when a < b. Also following properties should hold:
- compare(NaN, NaN) = 0
- NaN is bigger than any other number, so compare(NaN, any) = 1 and compare(any, NaN) = -1.
- compare(-0.0, 0.0) = -1 and compare(0.0, -0.0) = 1. Other numbers are ordered by default.
Other way to define: function should behave as Double.compare method in Java.
compare=(a,b)=>Math.sign(a-b||1/a-1/b||(b==b)-(a==a))\$\endgroup\$