Interactive online courses HTML Academy
2026-03-09 10:58 Diff
  • script.js

JavaScript

var usersByDay = [4, 2, 1, 3]; console.log(usersByDay); 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'); /* console.log(usersByDay); currentIndex = 0; 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'); */ /* console.log(usersByDay); currentIndex = 0; 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'); */

Thanks! We’ll fix everything at once!

Result

  1. Uncomment the first block of the code.
  2. In the uncommented code, change the value currentIndex to 1.
  3. Uncomment the second block of the code.
  4. In the uncommented code, change the value currentIndex to 2.