/** * */ var BubbleSort = function() { this.instructions = []; }; BubbleSort.prototype = Object.create(Sorter.prototype); /** * */ BubbleSort.prototype.sort = function(arr) { var i; var swapped = false; var len = arr.length; // NOTE this starts at the beginning of the array each time for (i = 1; i < len; i++) { if (arr[i - 1].value > arr[i].value) { this.swap(arr, i, i - 1); swapped = true; // console.log(dump(arr)); } } if (swapped === true) { this.sort(arr); } return arr; };