/** * */ var Mergesort = function() { this.instructions = []; }; Mergesort.prototype = Object.create(Sorter.prototype); /** * */ Mergesort.prototype.addInstruction = function(operation, left, right, mid) { console.log({ operation: operation, left: left, right: right, mid: mid }); this.instructions.push({ operation: operation, left: left, right: right }); }; var count = 0; /** * */ Mergesort.prototype.sort = function(arr, start, end) { count++; if (count > 30) { console.error('count exceeded'); return; } if (start >= end) { this.addInstruction('single', start, end, null); return; } var mid = start + Math.floor((end - start) / 2); // this.addInstruction('init', start, end, mid); this.sort(arr, start, mid); this.sort(arr, mid + 1, end); return; };