Skip to content

Instantly share code, notes, and snippets.

@KR1470R
Created July 12, 2020 07:31
Show Gist options
  • Select an option

  • Save KR1470R/b27ca2739987431d77f7d391c1c71b13 to your computer and use it in GitHub Desktop.

Select an option

Save KR1470R/b27ca2739987431d77f7d391c1c71b13 to your computer and use it in GitHub Desktop.

Revisions

  1. KR1470R created this gist Jul 12, 2020.
    12 changes: 12 additions & 0 deletions bubble_sort.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    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)