- 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 condition after the variable
minValue, save the valueusersByDay[currentIndex]to variableswap. Write the remaining code inside the condition. - On the next line in
usersByDay[currentIndex], write down the minimum value. - Then write value of variable
swapinusersByDay[j]. - On the next line, log in the console:
'Swapping ' + swap + ' and ' + minValue. - Below, log in the console:
'Current array: ' + usersByDay.
Comments