Here you can find the source of bubbleSort()
Array.prototype.bubbleSort = function() { var sorted = false; while (sorted === false) { sorted = true;//from www .j av a2 s . c om 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; sorted = false; } } } return this; }; console.log([4,6,3,8,9,3,5,2,1].bubbleSort()); var subStrings = function (str) { var result = []; for (var i = 0; i < str.length; i++) { for (var j = i + 1; j < str.length + 1; j++) { var sub = str.slice(i, j); if (result.indexOf(sub) === -1) { result.push(sub); } } } return result; }; console.log(subStrings("cat"));
Array.prototype.bubbleSort = function(){ var sorted = false; while(sorted !== true) { sorted = true; for(var i = 0; i < (this.length - 1); i++){ var left = this[i]; var right = this[i + 1]; if(left > right){ sorted = false; ...
Array.prototype.bubbleSort = function () { for (var i = 0; i < this.length - 1; i++) { var temp = null; 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; }; ary = [3, 2, 1]; console.log(ary.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]) { sorted = false; var tempNum = this[i]; this[i] = this[i + 1]; ...
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 dummy = this[i]; this[i] = this[j]; this[j] = dummy; }; }; ...
Array.prototype.bubbleSort = function () { for (var i = 0; i < this.length; i++) { for (var j = 0; j < this.length - 1; j++) { if (this[j] > this[j+1]){ var placeholder = this[j+1] this[j+1] = this[j]; this[j] = placeholder; return this;
"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]; ...
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]; ...
"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 ) { ...
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; ...