Nodejs Utililty Methods Array Bubble Sort

List of utility methods to do Array Bubble Sort

Description

The list of methods to do Array Bubble Sort are organized into topic(s).

Method

bubblesort()
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;
bubblesort()
Array.prototype.bubblesort = function () {
    'use strict';
    var swap,
        i,
        lastIndex = this.length - 1;
    do {
        swap = false;
        for (i = 0; i < lastIndex; i++) {
            if (this[i] > this[i + 1]) {
...
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;
    return this;
console.log([6,4,0, 3,-2,1].BubbleSort());
myBubbleSort()
function myBubbleSort(arr) {
  var length = arr.length;
  for (var i = 0; i < length; i++) {
    for (var j = 0; j < (length - i - 1); j++) {
      if(arr[j] > arr[j+1]) {
        var tmp = arr[j];
        arr[j] = arr[j+1];
        arr[j+1] = tmp;
  return arr;
Array.prototype.myBubbleSort = function () {
  var length = this.length;
  for (var i = 0; i < length; i++) {
    for (var j = 0; j < (length - i - 1); j++) {
      if(this[j] > this[j+1]) {
        var tmp = this[j];
        this[j] = this[j+1];
        this[j+1] = tmp;
  return this;
};