Created
December 24, 2020 06:22
-
-
Save chetans9/0b885332cf132d2ec3b1573aaf8f0a03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Bubble Sort in Javascript | |
var data = [23,87,21,3,9,11,98,45,31]; | |
for(var i=0; i< data.length; i++){ | |
//Last i digits already sorted | |
for(var j = 0; j < (data.length - i - 1); j++){ | |
if(data[j+1] < data[j]){ | |
var temp = data[j]; | |
data[j] = data[j+1]; | |
data[j+1] = temp; | |
} | |
} | |
} | |
console.log(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment