var largestNumber = function (nums) {
let comp = (a, b) => {
a = a.split("").reverse().join("");
b = b.split("").reverse().join("");
return a.localeCompare(b) > 0 ? 1 : 0;
};
return nums.map(v => '' + v).sort(comp).reverse().join('');
};
console.log(largestNumber([3, 30, 34, 5, 9]));
In nodejs
output: 9534330
In javascript
output: 9534303
What is happening?
array.sort()method: twitter.com/mathias/status/1036626116654637057numeric: trueoption oflocaleComparewhile the other may not...return a.localeCompare(b);. If you do so, you will get consistent outputs in both engines - which is9534330.