As described by Grundy, the main point here is the use of the sort method. In essence, the lensort function is a “selection criterion”. Those. the sort method gives the lensort method 2 values. Those. in the first step, it gave the values arr[0] and arr[1] ( 'bla','hahahah') . Next, I will mark in the code what and how:
function lensort(a,b) { var s1 = "" + a; // Это первый параметр или arr[0] var s2 = "" + b; // это второй параметр или arr[1] // по сути тут мы однозначно получаем строки s1 и s2 типа string if(s1.length < s2.lenght){ return false; // элементы на своих позициях по возрастанию } else if(s1.length > s2.length){ return true; // элемент arr[0] больше и его мы будет "двигать" вправо по массиву } }
As a result, when your lensort function returns true , the sort method makes the decision that the first element is “larger” than the second and mixes it to the right. And then the iteration moves further and compares the other 2 values, for example arr[1] and arr[2] (depending on the algorithm, the first element can be compared with all remaining ones, or using the bubble method, etc., see "sorting algorithms")