Sorting algorithms/Bubble sort: Difference between revisions

→‎{{header|JavaScript}}: Added real version for two js implementation.
m (Missed a few works with's)
(→‎{{header|JavaScript}}: Added real version for two js implementation.)
Line 364:
return this;
}
 
{{works with|SEE|3.0}}
{{works with|OSSP js|1.6.20070208}}
Array.prototype.bubblesort = function() {
var done = false;
while (! done) {
done = true;
for (var i = 1; i < this.length; i++) {
if (this[i - 1] > this[i]) {
done = false;
var tmp = this[i - 1];
this[i - 1] = this[i];
this[i] = tmp;
}
}
}
return this;
}
 
Example:
var my_arr = ["G", "F", "C", "A", "B", "E", "D"];
my_arr.bubblesort();
print(my_arr);
 
Output:
A,B,C,D,E,F,G
 
=={{header|MAXScript}}==
Anonymous user