<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Завершаем сортировку — Массивы — HTML Academy</title>
</head>
<body>
<script src="js/index.js"></script>
</body>
</html>
/*Downloaded from https://www.codeseek.co/a1ip/andx417andx430andx432andx435andx440andx448andx430andx435andx43c-andx441andx43eandx440andx442andx438andx440andx43eandx432andx43aandx443-andx2014-andx41candx430andx441andx441andx438andx432andx44b-andx2014-html-academy-KZXNLJ */
var usersByDay = [4, 2, 1, 3];
console.log(usersByDay);
// Начните цикл здесь
// Сортировка с первого элемента
for (var currentIndex = 0; currentIndex <= usersByDay.length - 2; currentIndex++) {
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('Меняю местами ' + swap + ' и ' + minValue);
console.log('Массив сейчас: ' + usersByDay);
}
}
console.log('На позиции ' + currentIndex + ' находится минимальный элемент ' + minValue);
} // Завершите цикл здесь