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 w  w.ja  v  a  2s. c  o m
    for (var i = 0; i < this.length - 1; i++) {
      if (this[i + 1] < this[i]) {
        var current_item = this[i];
        this[i] = this[i + 1];
        this[i + 1] = current_item;
        sorted = false;
      }
    }
  }
  return this;
}
// console.log([1, 3, 2, 5, 7, 3].bubbleSort());



function substrings(str) {
  var newArray = [];
  for(var i = 0; i < str.length; i++) {
    for(var j = i; j < str.length; j++) {
      var substr = str.slice(i, j + 1);
      if (newArray.indexOf(substr) === -1) {
        newArray.push(substr);
      }
    }
  }

  return newArray;
}

console.log(substrings("cat"));

Related

  1. bubbleSort()
    Array.prototype.bubbleSort = function() {
      var sorted = false;
      while (sorted === false) {
        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;
    ...
    
  2. bubbleSort()
    "use strict";
    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 tmp = this[i];
            this[i] = this[i + 1];
    ...
    
  3. bubbleSort()
    Array.prototype.bubbleSort = function() {
      let sorted = false;
      while (sorted === false) {
        sorted = true;
        for (let i = 0; i < this.length - 1; i++) {
          let j = i + 1;
          if (this[i] > this[j]) {
            let first = this[i];
            let second = this[j];
    ...
    
  4. bubbleSort()
    "use strict";
    Array.prototype.bubbleSort = function() {
      var sorted = false;
      var arr = this;
      var oneIteration = function() {
        for(var i = 0; i < arr.length - 1; i++) {
          var first = arr[i]
          var second = arr[i+1]
          if( first > second ) {
    ...
    
  5. bubbleSort()
    Array.prototype.bubbleSort = function() {
      while(true) {
        let doneSorting = true;
        for (i=0; i < this.length-1; i++) {
          if (this[i+1] < this[i]) {
            let tempI = this[i];
            this[i] = this[i+1];
            this[i+1] = tempI;
            doneSorting = false;
    ...
    
  6. bubbleSort()
    Array.prototype.bubbleSort = function () {
      var isSorted = false;
      while (!isSorted) {
        isSorted = true;
        for (var i = 0; i < (this.length - 1); i++) {
          if (this[i] > this[i + 1]) {
            var tmp = this[i];
            this[i] = this[i + 1];
            this[i + 1] = tmp;
    ...
    
  7. bubbleSort()
    Array.prototype.bubbleSort = function () {
      let flag = false;
      while (flag === false) {
        flag = true;
        let i = 0;
        for (let j = i + 1; j < this.length; j++) {
          if (this[i] > this[j]) {
            flag = false;
            let holder = this[i];
    ...
    
  8. bubbleSort()
    Array.prototype.bubbleSort = function() {
      let sorted = false;
      while (!sorted){
        sorted = true;
        for (let i = 0; i < this.length - 1; i++) {
          let j = i + 1;
          if (this[i] > this[j]) {
            sorted = false;
            [this[i], this[j]] = [this[j], this[i]];
    ...
    
  9. bubbleSort()
    "use strict";
    Array.prototype.bubbleSort = function () {
      let isSorted = false;
      while (!isSorted) {
        isSorted = true;
        for (let i = 0; i < (this.length - 1); i++) {
          if (this[i] > this[i + 1]) {
            let tmp = this[i];
            this[i] = this[i + 1];
    ...