Consider following data for testing the scenario.
When I use sort method on array with comparison function:
['a', 7, 65, '65'].sort((a,b) => a-b)
Output for Mozilla:
[ 7, 65, "65", "a" ]
Output for Chrome
["a", 7, 65, "65"]
The output seems to be different in both. Please focus on the reason why this happens rather than giving the solution on how to sort.
The objective of this question is to understand why is there a different implementation of sorting when it compares NaN in different engines.
Example: 'a' - 65 will return Nan;
[Update]
Sorting ['a', 65].sort((a,b) => a-b)
Chrome: [65, 'a']
Mozilla: ['a', 65]
Sorting [65, 'a'].sort((a,b) => a-b)
Chrome: ['a', 65]
Mozilla: [65, 'a']
Why does this behavior happen