Nodejs Array Bubble Sort bubble()

Here you can find the source of bubble()

Method Source Code

'use strict';//from   w  ww .j a  v a2s.c  o m
Array.prototype.bubble = function (){
   var i = this.length,
      tem,
      j;

   while (i>0){
      for (j=0; j < i -1; j++ ){
         if (this[j] > this[j+1]){
            tem = this[j];
            this[j] = this[j+1];
            this[j+1] = tem;
         }
      }
      i--;
   }
   console.log(this);
}
var array = [5,4,3,8,2];
array.bubble();

Related

  1. bubbleSort()
    function bubbleSort(){
      var moves = 0;
      if(typeof this !== typeof []){
        throw  new TypeError('argument is not a array');
      var length = this.length;
      for(var j = 0; j < this.length; j++){
         for(var i = 0; i < length; i++){
          if(isNaN(this[i])){
    ...
    
  2. 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]) {
            let temp = this[i];
            this[i] = this[i+1];
            this[i+1] = temp;
    ...
    
  3. bubbleSort()
    Array.prototype.bubbleSort = function(){
      var array = this
      var size = array.length
      var tmp
      for(var i = 0; i < size; i++)
        for(var j = 0; j < size; j++)
          if(array[i] > array[j]){
            tmp = array[j]
            array[j] = array[i]
    ...
    
  4. bubbleSort()
    Array.prototype.bubbleSort = function() {
      var len = this.length
      var tmp
      for(var i = 1; i < len; i++) {
        for(var j = i; j > 0; j--) {
          if(this[j] < this[j-1]) {
            tmp = this[j]
            this[j] = this[j-1]
            this[j-1] = tmp
    ...
    
  5. bubbleSort()
    Array.prototype.bubbleSort = function() {
      var flag= false;
      while(!flag){
        flag=true;
        for (var i = 0; i < this.length-1; i++) {
        if (this[i] > this[i+1]){  
            var x = this[i+1];  
            this[i+1] = this[i];  
            this[i] = x;  
    ...