Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
setTimeOut no funciona en la función recursiva

Estoy creando un visualizador de clasificación. Para los algoritmos de clasificación iterativos, mi código funciona perfectamente, pero no funciona para la clasificación rápida y la clasificación por fusión. La función no espera e inmediatamente devuelve la salida, pero tengo que mostrar los cambios lentamente mediante animaciones. El siguiente es mi código.

 const delay = (time) => { return new Promise((resolve) => setTimeout(resolve, time)); }; const quickSortHelper = async(arr, a, b) => { if (b > a) { document.getElementById(a).style.backgroundColor="green" let pivot = getPivot(arr, a, b) await delay(2*animationSpeed) setArray([...arr]) document.getElementById(a).style.backgroundColor="#343434" await delay(2*animationSpeed) quickSortHelper(arr, a, pivot - 1) await delay(4*animationSpeed) quickSortHelper(arr, pivot + 1, b) } } const quickSort = () => { setStartSorting(true) let arr = [...array] console.log(arr); quickSortHelper(arr, 0, arr.length - 1) console.log('ended'); setStartSorting(false) } const getPivot = (arr, a, b) => { let pivot = arr[a] var i = a var j = b while (j > i) { while (pivot >= arr[i] && i<=b) { i++ } while (pivot < arr[j] && j>=a) { j-- } if (j > i) { let temp = arr[i] arr[i] = arr[j] arr[j] = temp } } let temp =pivot arr[a] = arr[j] arr[j] = temp return j }

El archivo console.log('finalizado') se ejecuta inmediatamente tan pronto como ejecuto la función y los estados también se actualizan inmediatamente.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!