Here you can find the source of bubbleSort()
Array.prototype.bubbleSort = function () { var unsorted = true; while (unsorted) { unsorted = false;/*from ww w .j a va 2s. c o m*/ 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; unsorted = true; } } } return this; }; // a = [1,7,3,9,3,4,2,7,4,0]; // // console.log(a.bubbleSort()); var subStrings = function (word) { var res = []; for (i = 0; i < word.length; i++) { for (j = i + 1; j <= word.length; j++) { res.push(word.substring(i,j)); } } return res; } console.log(subStrings("cat"));
Array.prototype.bubbleSort = function () { var i, j, temp; for (var i = 0; i < this.length; i++) { for (var j = 0; j < this.length - 1 - i; j++) { if (this[j] > this[j + 1]) { temp = this[j]; this[j] = this[j + 1]; this[j + 1] = temp; return this; }; var num = [22, 34, 3, 32, 82, 55, 89, 50, 37, 5, 64, 35, 9, 70]; num.bubble_sort(); for (var i = 0; i < num.length; i++) document.body.innerHTML += num[i] + " ";
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; ...
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; };
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; ...
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]
Array.prototype.bubbleSort = function(){ var sorted = false; while(!sorted) { sorted = true; 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; ...
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; };
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; ...
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]; ...