Created
January 30, 2019 18:04
-
-
Save jharris-code/6201b8fbdc3e17e47ccebed591bb5237 to your computer and use it in GitHub Desktop.
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
| function bubbleSort(arr) { | |
| let swapped = true; | |
| while(swapped){ | |
| swapped = false; | |
| for(let j = 0; j < arr.length - 1; j++){ | |
| if(arr[j] > arr[j+1]){ | |
| swapped = true; | |
| let temp = arr[j]; | |
| arr[j] = arr[j+1]; | |
| arr[j+1] = temp; | |
| } | |
| } | |
| } | |
| return arr; | |
| } | |
| //outputs [1,2,3,4,5,6,7,8] | |
| console.log(bubbleSort([1,2,5,3,7,8,6,4])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment