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

130
Views
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
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!