0 added
0 removed
Original
2026-01-01
Modified
2026-03-09
1
<ul><li>script.js</li>
1
<ul><li>script.js</li>
2
</ul><p>JavaScript</p>
2
</ul><p>JavaScript</p>
3
<p>var usersByDay = [4, 2, 1, 3]; console.log(usersByDay); // Start loop here // Sorting from the first element var currentIndex = 0; var minValue = usersByDay[currentIndex]; for (var j = currentIndex + 1; j <= usersByDay.length - 1; j++) { if (usersByDay[j] < minValue) { minValue = usersByDay[j]; var swap = usersByDay[currentIndex]; usersByDay[currentIndex] = minValue; usersByDay[j] = swap; console.log('Swapping ' + swap + ' and ' + minValue); console.log('Current array: ' + usersByDay); } } console.log('Minimum element ' + minValue + ' is on ' + currentIndex + 'position'); // Complete loop here // Sorting from the second element console.log(usersByDay); currentIndex = 1; minValue = usersByDay[currentIndex]; for (var j = currentIndex + 1; j <= usersByDay.length - 1; j++) { if (usersByDay[j] < minValue) { minValue = usersByDay[j]; var swap = usersByDay[currentIndex]; usersByDay[currentIndex] = minValue; usersByDay[j] = swap; console.log('Swapping ' + swap + ' and ' + minValue); console.log('Current array: ' + usersByDay); } } console.log('Minimum element ' + minValue + ' is on ' + currentIndex + 'position'); // Sorting from the third element console.log(usersByDay); currentIndex = 2; minValue = usersByDay[currentIndex]; for (var j = currentIndex + 1; j <= usersByDay.length - 1; j++) { if (usersByDay[j] < minValue) { minValue = usersByDay[j]; var swap = usersByDay[currentIndex]; usersByDay[currentIndex] = minValue; usersByDay[j] = swap; console.log('Swapping ' + swap + ' and ' + minValue); console.log('Current array: ' + usersByDay); } } console.log('Minimum element ' + minValue + ' is on ' + currentIndex + 'position');</p>
3
<p>var usersByDay = [4, 2, 1, 3]; console.log(usersByDay); // Start loop here // Sorting from the first element var currentIndex = 0; var minValue = usersByDay[currentIndex]; for (var j = currentIndex + 1; j <= usersByDay.length - 1; j++) { if (usersByDay[j] < minValue) { minValue = usersByDay[j]; var swap = usersByDay[currentIndex]; usersByDay[currentIndex] = minValue; usersByDay[j] = swap; console.log('Swapping ' + swap + ' and ' + minValue); console.log('Current array: ' + usersByDay); } } console.log('Minimum element ' + minValue + ' is on ' + currentIndex + 'position'); // Complete loop here // Sorting from the second element console.log(usersByDay); currentIndex = 1; minValue = usersByDay[currentIndex]; for (var j = currentIndex + 1; j <= usersByDay.length - 1; j++) { if (usersByDay[j] < minValue) { minValue = usersByDay[j]; var swap = usersByDay[currentIndex]; usersByDay[currentIndex] = minValue; usersByDay[j] = swap; console.log('Swapping ' + swap + ' and ' + minValue); console.log('Current array: ' + usersByDay); } } console.log('Minimum element ' + minValue + ' is on ' + currentIndex + 'position'); // Sorting from the third element console.log(usersByDay); currentIndex = 2; minValue = usersByDay[currentIndex]; for (var j = currentIndex + 1; j <= usersByDay.length - 1; j++) { if (usersByDay[j] < minValue) { minValue = usersByDay[j]; var swap = usersByDay[currentIndex]; usersByDay[currentIndex] = minValue; usersByDay[j] = swap; console.log('Swapping ' + swap + ' and ' + minValue); console.log('Current array: ' + usersByDay); } } console.log('Minimum element ' + minValue + ' is on ' + currentIndex + 'position');</p>
4
<p>Thanks! We’ll fix everything at once!</p>
4
<p>Thanks! We’ll fix everything at once!</p>
5
<h2>Result</h2>
5
<h2>Result</h2>
6
<ol><li>Remove the entire code for sorting from the second and third elements.</li>
6
<ol><li>Remove the entire code for sorting from the second and third elements.</li>
7
<li>Then wrap the entire the code after the second line in a loop that increases the variable currentIndex from zero to usersByDay.length - 2 inclusively. Value of currentIndex must increase by one after each iteration.</li>
7
<li>Then wrap the entire the code after the second line in a loop that increases the variable currentIndex from zero to usersByDay.length - 2 inclusively. Value of currentIndex must increase by one after each iteration.</li>
8
<li>Inside this loop, remove the duplicate declaration of the variable currentIndex.</li>
8
<li>Inside this loop, remove the duplicate declaration of the variable currentIndex.</li>
9
</ol>
9
</ol>