Created
December 18, 2018 00:27
-
-
Save rajatk16/4bb6e8e1f70097ca4aafd773e1c21da9 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
| bubbleSort = (array) => { | |
| let swapped = false | |
| do { | |
| swapped = false | |
| array.forEach((current, i) => { | |
| console.log(array.join(' ')) | |
| if (current > array[i + 1]) { | |
| const temp = current | |
| console.log(array.join(' ')) | |
| array[i] = array[i + 1] | |
| array[i + 1] = temp | |
| swapped = true | |
| } | |
| }) | |
| } while(swapped) | |
| console.log(array.join(' ')) | |
| return array | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment