Posted By

mscribellito on 04/20/11


Tagged


Versions (?)

JavaScript Bubble Sort


 / Published in: JavaScript
 

  1. var Sort = {
  2.  
  3. bubble : function(a) {
  4. var i, j, t, n = a.length;
  5. for (i = 0; i < n; i++) {
  6. for (j = n - 1; j > i; j--) {
  7. if (a[j - 1] > a[j]) {
  8. t = a[j - 1];
  9. a[j - 1] = a[j];
  10. a[j] = t;
  11. }
  12. }
  13. }
  14. return a;
  15. }
  16.  
  17. };

Report this snippet  

You need to login to post a comment.