- 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];
}
}
console.log('Minimum element: ' + minValue);
Result
Goalscompleted
- Inside the if block, after the assignment to
minValue, declareswapand storeusersByDay[currentIndex]in it. Keep the remaining code for this task inside that block. - On the next line, assign the minimum value to
usersByDay[currentIndex]. - Then assign the value of
swaptousersByDay[j]. - On the next line, log in the console:
'Swapping ' + swap + ' and ' + minValue. - Below, log in the console:
'Current array: ' + usersByDay.
Comments