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

67
Views
El tipo de burbuja correcto en JS no hace nada

El código simplemente registra la misma matriz. ¿Qué parece estar mal aquí? Estoy usando el código VS.

 function bubbleSort(array) { for (let i = 0; i < array.length - 1; i++) { for (let j = 0; j < array.length - 1 - i; j++) { if (array[j] > array[j + 1]) { [array[j], array[j + 1] = array[j + 1], array[j]]; } } } return array; } let arr1 = [9, 4, 6, 4, 3]; console.log(bubbleSort(arr1));

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debería ser:

 [array[j], array[j + 1]] = [array[j + 1], array[j]];

en vez de:

 [array[j], array[j + 1] = array[j + 1], array[j]];

Preste mucha atención a dónde comienzan y terminan los corchetes.


Su código actual:

  1. asigna un índice de matriz a sí mismo
  2. crea una matriz con 3 elementos
  3. y lo tira inmediatamente

Lo que realmente quieres es una tarea de desestructuración . (¡gracias a @Reyno por el enlace!)

about 4 years ago · Juan Pablo Isaza Report
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!