Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
Javascript Quick Sort Algorithm

I've been brushing up on some forgotten skills for a interview recently, mainly sorting algorithms, and I've come across two different ways to do quick sort and I'm having trouble telling which one is the proper way of doing it. Does anyone know which one is correct?

Version 1:

const quickSort(arr, start, end){
  if (start >= end) {
        return;
  }
    
  let index = partition(arr, start, end);

  quickSort(arr, start, index - 1);
  quickSort(arr, index + 1, end);
}

function partition(arr, start, end){
  const pivotValue = arr[end];
  let pivotIndex = start;

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

Version 2:

function QuickSort(Arr){
  if(Arr.length < 2) return Arr;

  const pivot = Arr[0];
  const leftArr = [];
  const rightArr = [];

  for(let i = 1; i < Arr.length; i++){
    if(Arr[i] < pivot){
      leftArr.push(Arr[i]);
    }
    else{
      rightArr.push(Arr[i])
    }
  }

  return [...QuickSort(leftArr), pivot, ...QuickSort(rightArr)];
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda