Nodejs Array Bubble Sort bubbleSort()

Here you can find the source of bubbleSort()

Method Source Code

Array.prototype.bubbleSort = function(){
  var sorted = false;

  while(!sorted) {
    sorted = true;// w ww  .j ava  2  s  .c  o  m
    for(var index = 0; index < this.length - 1; index++) {

      if(this[index] > this[index + 1]) {
        var holder = this[index];
        this[index] = this[index + 1];
        this[index + 1] = holder;

        sorted = false;
      }
    }
  }

  return this;
}

Related

  1. bubbleSort()
    Array.prototype.bubbleSort = function() {
      let sorted = false;
      while (sorted === false) {
        sorted = true;
        for (var i = 0; i < this.length; i++) {
          let first = this[i];
          let second = this[i+1];
          if (first > second){
            this[i] = second;
    ...
    
  2. bubbleSort()
    Array.prototype.bubbleSort = function() {
      for(var i=0; i<this.length-1; i++) {
        for(var j=(i+1); j<this.length; j++) {
          if (this[i] > this[j]) {
            var temp = this[i];
            this[i] = this[j];
            this[j] = temp;
    };
    
  3. bubbleSort()
    Array.prototype.bubbleSort = function () {
      var sorted = false;
      while (!sorted) {
        sorted = true;
        for (var i = 0; i < this.length - 1; i++) {
          if (this[i] > this[i+1]) {
            var temp = this[i];
            this[i] = this[i+1];
            this[i+1] = temp;
    ...
    
  4. bubbleSort()
    Array.prototype.bubbleSort = function () {
      for (var i = 0; i < this.length; i++) {
        for (var j = i + 1; j < this.length; j++) {
          if (this[i] > this[j]) {
            var temp = this[i];
            this[i] = this[j];
            this[j] = temp;
      return this
    };
    var arr = [5,4,67,2,3,7,1,8]
    
  5. bubbleSort()
    Array.prototype.bubbleSort = function () {
      var unsorted = true;
      while (unsorted) {
        unsorted = false;
        for (i = 0; i < this.length - 1; i++) {
          if (this[i] > this[i+1]) {
            var temp = this[i];
            this[i] = this[i+1];
            this[i+1] = temp;
    ...
    
  6. bubbleSort()
    Array.prototype.bubbleSort = function () {
      let sorted = false;
      while (!sorted) {
        sorted = true;
        for (let i = 0; i < this.length - 1; i++) {
          if (this[i] > this[i + 1]) {
            sorted = false;
            [this[i], this[i+1]] = [this[i+1], this[i]];
      return this;
    };
    
  7. bubbleSort()
    Array.prototype.bubbleSort = function() {
      var sorted = false;
      while (!sorted) {
        sorted = true;
        for(var i = 0; i < this.length - 1; i++) {
          if (this[i] > this[i + 1]) {
            var temp = this[i];
            this[i] = this[i + 1];
            this[i + 1] = temp;
    ...
    
  8. bubbleSort()
    Array.prototype.bubbleSort = function () {
      var sorted = false;
      while (!sorted) {
        sorted = true;
        for (var i = 0; i < this.length; i++) {
          if (this[i] > this[i + 1]) {
            sorted = false;
            var intermediate = this[i];
            this[i] = this[i + 1];
    ...
    
  9. bubbleSort()
    Array.prototype.bubbleSort = function () {
      var sorted = false;
      do {
        sorted = true;
        for (var i = 0; i < this.length - 1; i++) {
          var j = i + 1;
          if (this[i] > this[j]) {
            var temp = this[i];
            this[i] = this[j];
    ...