var shellSort = function(arr) { var n = arr.length; for (var gap = n / 2 | 0; gap > 0; gap = gap / 2 | 0) { for (var groupIndex = 0; groupIndex < gap; groupIndex++) { for (var currIndex = groupIndex + gap; currIndex < n; currIndex += gap) { var cur = arr[currIndex]; var pre = currIndex - gap; while (pre >= groupIndex && cur < arr[pre]) { arr[pre + gap] = arr[pre]; pre -= gap; } arr[pre + gap] = cur; } } } };