0
What is meaning of useing (-Infinity, Infinity) in sorting
function myFunction(arr) {<br> var len = arr.lenght;<br> var max = -Infinity;<br> while(len--) {<br> if(arr[len] > max) {<br> <br> max = arr[len];<br> }<br> }<br> return max;<br> }
1 ответ
+ 2
The code you attached is not readable, invalid JavaScript code (probably copy-pasted from somewhere).
It is better to save your program in the web playground, and provide a link with "Insert code" feature.
-Infinity might be used in this snippet to represent a number that is smaller than any other number. So that the algorithm is always able to do a meaningful comparison on all elements of the list, and always return a result.