function partition(arr, start, end) {
let pivotValue = arr[end - 1]
let pivotIndex = start
for (let i = start; i < end - 1; ++i) {
let elementValue = arr[i]
if (elementValue < pivotValue) {
arr[i] = arr[pivotIndex]
arr[pivotIndex] = elementValue
pivotIndex++
}
}
arr[end - 1] = arr[pivotIndex]
arr[pivotIndex] = pivotValue
return pivotIndex
}