- script.js
JavaScript
var usersByDay = [4, 2, 1, 3];
console.log(usersByDay);
for (var i = 0; i <= usersByDay.length - 2; i++) {
var minValue = usersByDay[i];
for (var j = i + 1; j <= usersByDay.length - 1; j++) {
if (usersByDay[j] < minValue) {
minValue = usersByDay[j];
var swap = usersByDay[i];
usersByDay[i] = minValue;
usersByDay[j] = swap;
}
}
}
Result
Goalscompleted
- Inside the loop, log in the console array
usersByDay
. - Change initial value
usersByDay
to[5, 4, 3, 2, 1, 0]
. - Change initial value
usersByDay
to[0, 1, 2, 3, 4, 5]
. - Change initial value
usersByDay
to[812, 1360, 657, 1247]
. - Change initial value
usersByDay
to[812, 1360, 657, 1247, 165]
.
Comments