Created
April 21, 2021 16:49
-
-
Save Fernando74lr/f18f6241c198134a5839e6aa67c6b34c to your computer and use it in GitHub Desktop.
Simple Bubble Sort algorithm using JavaScript
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
let nums = [54, 26, 93, 17, 77, 31, 44, 55, 20]; | |
let temp = 0, count = 0; | |
while(count != nums.length) { | |
nums.forEach(function(num, i) { | |
if (num > nums[i + 1]) { | |
temp = nums[i + 1]; | |
nums[i + 1] = num; | |
nums[i] = temp; | |
} | |
}); | |
count++; | |
} | |
console.log(nums); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment