code: function quickSort(arr) {
  
    /* recursion anchor: one element is always sorted */
    if (arr.length <= 1) return arr;
  
    /* randomly selecting some value */
    var median = arr[Math.floor(Math.random() * arr.length)];
    var arr1 = [],
        arr2 = [],
        arr3 = [],
        i = void 0;
    for (i in arr) {
      if (arr[i] < median) {
        arr1.push(arr[i]);
      }
      if (arr[i] === median) {
        arr2.push(arr[i]);
      }
      if (arr[i] > median) {
        arr3.push(arr[i]);
      }
    }
  
    /* recursive sorting and assembling final result */
    return quickSort(arr1).concat(arr2).concat(quickSort(arr3));
  }
docs: /*
  Quick Sort:
  1. Select some random value from the array, the median.
  2. Divide the array in three smaller arrays according to the elements
  being less, equal or greater than the median.
  3. Recursively sort the array containg the elements less than the
  median and the one containing elements greater than the median.
  4. Concatenate the three arrays (less, equal and greater).
  5. One or no element is always sorted.
  TODO: This could be implemented more efficiently by using only one array object and several pointers.