I was practicing my skills on CodeWars and I got a problem where I had to find the unique number in the given array. My solution needed to sort a integer array first, thus I had to use this arr.sort(function (a,b) { return a - b })
. Because I did it the way I did, it is just complaining that I've exceeded the maximum call stack size. Is there any way I can sort arrays without using the aforementioned method. Code in question:
function findUniq(arr) {
arr.sort(function (a,b) { return a - b })
if (arr[0] == arr[1]) { return Math.max(...arr) }
else { return Math.min(...arr) }
}