Nodejs Array Bubble Sort bubbleSort_bubbleSorter;

Here you can find the source of bubbleSort_bubbleSorter;

Method Source Code

function _bubbleSorter(sortMe){

  if(!Array.isArray(sortMe)){
    throw new TypeError('Your sortMe needs to be an array');
  }//from w w w. ja v  a  2 s  . c  o m

  for(var j = 0; j < sortMe.length; j++){
    for(var i = 0; i < sortMe.length; i++){
      if(sortMe[i] > sortMe[i+1]){
        var tempNum = sortMe[i];
        sortMe[i] = sortMe[i+1];
        sortMe[i + 1] = tempNum;
      }
    }
  }
  return sortMe;
}

//Setting the bubble short to the Array prototype
Array.prototype.bubbleSort = _bubbleSorter;

module.exports = {

  bubbleSorter : _bubbleSorter

};

Related

  1. bubbleSort()
    function bubbleSort(arr){
      var bubbledArr = arr;
      var isSwapped = false;
      var count = 0;
      while(!isSwapped) {
        isSwapped = false;
        var moves = 0;
        for(var i = 0; i < bubbledArr.length -1; i++){
          var curr = bubbledArr[i];
    ...
    
  2. bubbleSort()
    Array.prototype.bubbleSort = function (){
      let isSorted = false; 
      while(!isSorted){ 
        isSorted = true;
        for (var i = 0; i < this.length; i++){
          if (this[i] > this[i+1]){ 
            let earlierNum = this[i];
            this[i] = this[i + 1];
            this[i + 1] = earlierNum;
    ...
    
  3. bubbleSort()
    Array.prototype.bubbleSort = function(){
      var len = this.length;
      var exchange = false;
      var temp;
      for(var i = 1;i < len;i++){
        for(var j = 0;j < len - i;j++){
          if(this[j] > this[j+1]){
            temp = this[j];
            this[j] = this[j+1];
    ...
    
  4. bubbleSort()
    Array.prototype.bubbleSort = function () {
        for (var i = this.length-1; i > 0; i--) {
            for (var j = 0; j < i; j++) {
                if(this[j] > this[j+1]) {
                    this.swap(j, j+1);
    };
    ...
    
  5. bubbleSort(arr)
    Array.prototype.bubbleSort = function(arr) {
      if(arr !== undefined) {
        this.array = arr.map(function(element){
          return element;
        });
      } else {
        this.array = this.map(function(element){
          return element;
        });
    ...
    
  6. bubbleSort()
    'use strict';
    Array.prototype.bubbleSort = function bubbleSort() {
      let sorted = false;
      while(!sorted) {
        sorted = true;
        for (let i = 0; i < this.length - 1; i++) {
          if (this[i] > this[i+1]) {
            sorted = false;
            let temp = this[i+1];
    ...
    
  7. bubble_sort()
    Array.prototype.bubble_sort = function() {
      var sorted = false
      var passes = 0
      var n = 0
      while(!sorted) {
        sorted = true
        for(var i = 1; i < this.length; i++) {
          if(this[i] < this[i-1]) {
            this.swap(i, i-1)
    ...
    
  8. 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;
            var tmp = this[i - 1];
            this[i - 1] = this[i];
    ...
    
  9. 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;