Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
m (→[[Perl]]) |
(adding JavaScript implementation) |
||
Line 201: | Line 201: | ||
Just xs2 -> Just $ x:xs2 |
Just xs2 -> Just $ x:xs2 |
||
_bsort _ = Nothing |
_bsort _ = Nothing |
||
==[[JavaScript]]== |
|||
[[Category:JavaScript]] |
|||
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; |
|||
[this[i-1], this[i]] = [this[i], this[i-1]] |
|||
} |
|||
} |
|||
} |
|||
return this; |
|||
} |
|||
==[[Perl]]== |
==[[Perl]]== |