Created
November 19, 2017 19:25
-
-
Save kaz-a/6c6fb2f1d0447eb5f5ab9ad203ea0eb8 to your computer and use it in GitHub Desktop.
Bubble sort algorithm
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
const bubbleSort = arr => { | |
for (let i=arr.length-1; i>=0; i--){ | |
for(let j=1; j<=i; j++){ | |
if(arr[j-1]>arr[j]){ | |
var temp = arr[j-1]; | |
arr[j-1] = arr[j]; | |
arr[j] = temp; | |
} | |
} | |
} | |
return arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment