Sure, we were supposed to sort randomly and sort() expects a function that compares two values and returns >0 if greater 0 if equal and <0 if lesser, so,
For the random order, I used Math.random that returns a value between 0 and 1
To be sure that it can return a negative number I multiplied the random times number * 2 so:
number * 2
Math.random < 0.5
Math.random == 0.5
Math.random > 0.5
However, since we have three possible cases it could be better to do something like:
.sort(number => number - Math.floor(Math.random() * number * 3));
That way there is a 33.33% of probability for each case.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.