/** * */ var InsertionSort = function() { this.instructions = []; }; InsertionSort.prototype = Object.create(Sorter.prototype); /** * */ InsertionSort.prototype.sort = function(arr) { var len = arr.length; var i; var j; var tmp; var swaps = 0; var comparisons = 0; for (i = 0; i < len; i++) { for (j = i; j > 0; j--) { comparisons++; if (arr[j - 1].value > arr[j].value) { swaps++; tmp = arr[j - 1]; arr[j - 1] = arr[j]; arr[j] = tmp; } else { break; } } } return arr; };