Simple bubble sort by: https://dev.to/seanwelshbrown
Created
April 18, 2021 11:12
-
-
Save GGrassiant/e518dca88c73aa39977fa9271d9db6c5 to your computer and use it in GitHub Desktop.
Simpe Bubble Sort
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 = (array) => { | |
| let isSorted = false; | |
| while (!isSorted) { | |
| isSorted = true; | |
| for (let i = 0; i < array.length - 1; i++) { | |
| if (array[i] > array[i + 1]) { | |
| [array[i], array[i + 1]] = [array[i + 1], array[i]]; | |
| isSorted = false; | |
| } | |
| } | |
| } | |
| return array; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment