<commit_before>module.exports = quickSort

function quickSort(input, left = 0, right = input.length - 1) {
  if (input.length > 1) {
    const pivot = partition(input, left, right)
    if (left < pivot - 1) quickSort(input, left, pivot - 1)
    if (pivot < right) quickSort(input, pivot, right)
  }

  return input
}

function partition(array, left, right) {
  const pivot = array[Math.floor((left + right) / 2)]
  while (left <= right) {
    while (array[left] < pivot) left++
    while (array[right] > pivot) right--

    if (left <= right) {
      swap(array, left, right)
      left++
      right--
    }
  }

  return left
}

function swap(array, left, right) {
  if (left === right) return
  let tmp = array[left]
  array[left] = array[right]
  array[right] = tmp
}<commit_msg>Refactor quicksort<commit_after>module.exports = quickSort

function quickSort(input, lo = 0, hi = input.length - 1) {
  if (hi - lo > 0) {
    const pivot = partition(input, lo, hi)
    quickSort(input, lo, pivot - 1)
    quickSort(input, pivot + 1, hi)
  }

  return input
}

function partition(input, lo, hi) {
  const pivot = hi
  let firstHigh = lo
  for (let i = lo; i < hi; i++) {
    if (input[i] < input[pivot]) {
      swap(input, i, firstHigh)
      firstHigh++
    }
  }
  swap(input, pivot, firstHigh)

  return firstHigh
}

function swap(input, left, right) {
  if (left === right) return
  let tmp = input[left]
  input[left] = input[right]
  input[right] = tmp
}
{'fraction_non_alphanumeric': 0.1430527036276523, 'fraction_numerical': 0.007529089664613279, 'mean_word_length': 2.983651226158038, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7036904', 'n_tokens_mistral': 535, 'n_tokens_neox': 506, 'n_words': 151}