var a = ['S', 'O', 'R', 'T', 'E', 'X', 'A', 'M', 'P', 'L', 'E']; function qSort(from, to) { if (from >= to) { return; } var pivot = a[to]; var counter = from; for (var i = from; i < to; i++) { if (a[i] < pivot) { qSwap(i, counter); counter++; } } qSwap(counter, to); qSort(from, counter - 1); qSort(counter + 1, to); } function qSwap(x, y) { let temp = a[x]; a[x] = a[y]; a[y] = temp; } qSort(0, a.length - 1); console.log(a);