Created
July 12, 2020 07:31
-
-
Save KR1470R/b27ca2739987431d77f7d391c1c71b13 to your computer and use it in GitHub Desktop.
Bubble sort
This file contains hidden or 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 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