Why is 857 larger than 1000 and 1001? Javascript <p>I have the following problem, my function accepts an array that contains 4 arrays, each element is a number. The functions must return the largest element of each array. </p> <pre><code>function largestOfFour(arr) { var largest = []; for (var i = 0; i &lt; arr.length; i++) { largest.push(arr[i].sort().pop()); } console.log(largest); return largest; } largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); </code></pre> <p>Results: </p> <pre><code>Array [ 5, 27, 39, 857 ] </code></pre> <p>Apparently it works, but when I tried with the last array [1000, 1001, 857, 1], in which 1000 and 1001 are larger than 857 I'm getting 857. Why does it happen?</p>