Was working on this problem for some time now and decided to look at the hints for some help. I was under the assumption that the array was already sorted looking through the tests but I decided to look up the .sort guide found on the hint page:
I couldn’t help but notice this little function : function compareNumbers(a, b) { return a - b; }
Which is stated that putting 2 ints through the function would return the nums/array in ascending order. Can anyone help explain how this is being done? To me, it just looks like it returns a single value, a - b, but that isn’t the case.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
The how depends upon your browser, and its not really important.
A function that defines the sort order. The return value should be a number whose sign indicates the relative order of the two elements: negative if a is less than b, positive if a is greater than b, and zero if they are equal. NaN is treated as 0. The function is called with the following arguments:
The sign of the value returned by the sort function describes which element should come first. The .sort() method uses this comparison function to order the array.