Last active
December 30, 2016 20:56
-
-
Save leojh/4f131f6ab4d91991ce87be8805135477 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
const bubbleSort = arr => { | |
let didSwap = true | |
while(didSwap) { | |
didSwap = false | |
for(let i = 0; i < arr.length; i++) { | |
if (arr[i] > arr[i + 1]) { | |
const tmp = arr[i + 1] | |
arr[i + 1] = arr[i] | |
arr[i] = tmp; | |
didSwap = true | |
} | |
} | |
} | |
} | |
const arr = [9, 8, 7, 6, 5, 4, 3, 2, 1] | |
bubbleSort(arr) | |
$('#output').text(arr.join(' ')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment