- 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');
*/
Result
Goalscompleted
- Uncomment the first block of the code.
- In the uncommented code, change the value
currentIndex
to1
. - Uncomment the second block of the code.
- In the uncommented code, change the value
currentIndex
to2
.
Comments