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

133
Vistas
Bubble sort visualization help in js

i am very new to js, i previously learned python

var lineArray = [];

const sort = (arr) =>{
    let temp;
    for (var x = 0; x <= arr.length; x++) {
        if (arr[x] > arr[x+1]) {
            temp = arr[x];
            arr[x] = arr[x+1];
            arr[x+1] = temp;
            
        }
    }
}

const draw = () =>{
    const canvas = document.querySelector('#myCanvas');
    const width = canvas.width;
    
    ctx = canvas.getContext('2d');
    ctx.lineWidth = 2;
    ctx.strokeStyle = 'white';
    
    if (!canvas.getContext){
        return ;
    }
    
    for(var x = 1; x <= width; x++){
        let rand = Math.random();
        
        ctx.beginPath();
        ctx.moveTo(x,rand * 250);
        ctx.lineTo(x,250);
        ctx.stroke();
        
        lineArray.push(rand);
    }
}

draw();

I am trying to get a hang of the language by making a bubble sort visualizer in js but i seem to have hit a dead end lol, here is my code

I got how to make the lines but i have no idea how to sort them

Oh and in lineArray.push(rand); the i wasn't sure what values to add to the array so i did that...no idea if that works but i will go with it :)

any tips or any solutions are appreciated

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