I have an array that looks like this: values = [250, 200, 300, 150, 300]
Here is the code I am using:
for (var i = 0; i < values.length - 1; i += 1) {
if (values[i] > values[i + 1]) {
var temp = values[i + 1];
values[i + 1] = values[i];
values[i] = temp;
}
}
Unfortunately, this code is not producing the desired result. The current output is values = [200, 250, 150, 300, 300]
I am looking for a solution to achieve the correct sorting without relying on built-in functions.