Skip to content

Instantly share code, notes, and snippets.

@KR1470R
Created July 12, 2020 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KR1470R/b27ca2739987431d77f7d391c1c71b13 to your computer and use it in GitHub Desktop.
Save KR1470R/b27ca2739987431d77f7d391c1c71b13 to your computer and use it in GitHub Desktop.
Bubble sort
let arrJertva = [5,3,1,2]
let bubble_sort = arr=>{
for (let i=1,n=arr.length;i<n;i++) {//make bubble
for (let j=1;j<n;j++) { //iterate every element in bubble
if (arr[j] < arr[j-1]) {
[arr[j],arr[j-1]] = [arr[j-1],arr[j]] // swaping elements if they equally of condition
}
}
}
}
bubble_sort(arrJertva)
console.log(arrJertva)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment