Array.prototype.stableSort = function(cmp) { cmp = !!cmp ? cmp : (a, b) => { if (a < b) return -1; if (a > b) return 1; return 0; }; let stabilizedThis = this.map((el, index) => [el, index]); let stableCmp = (a, b) => { let order = cmp(a[0], b[0]); if (order != 0) return order; return a[1] - b[1]; } stabilizedThis.sort(stableCmp); for (let i=0; i bValue) return 1; return 0; } function orderStringSorter(a,b) { var aValue=a.children[1].innerHTML.substring(0,3); var bValue=b.children[1].innerHTML.substring(0,3); if ( aValue == "[x]" && bValue == "[ ]" ) return 1; if ( aValue == "[ ]" && bValue == "[x]" ) return -1; return 0; }