Skip to content

Instantly share code, notes, and snippets.

@Fernando74lr
Created April 21, 2021 16:49
Show Gist options
  • Save Fernando74lr/f18f6241c198134a5839e6aa67c6b34c to your computer and use it in GitHub Desktop.
Save Fernando74lr/f18f6241c198134a5839e6aa67c6b34c to your computer and use it in GitHub Desktop.
Simple Bubble Sort algorithm using JavaScript
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