Bubble sorting of an array

A simple example of bubble sorting for an array.
<!DOCTYPE html>
<html>
<head>
   
</head>
<body>

<script>
    
var myArray = [10, 120, 320, 401, 234, 213, 111, 101, 109];
 
function bubbleSorting(myArray)
{
    var isSwapped;
    do {
        isSwapped = false;
        for (var i=0; i < myArray.length-1; i++) {
            if (myArray[i] > myArray[i+1]) {
                var temp = myArray[i];
                myArray[i] = myArray[i+1];
                myArray[i+1] = temp;
                isSwapped = true;
            }
        }
    } while(isSwapped);
}
 
bubbleSorting(myArray);
console.log(myArray);
</script>

</body>
</html>

Responses

0 Replies