Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const bubbleSort = (array) => {
- let swaps = true;
- while (swaps) {
- swaps = false;
- for (let i = 0; i < array.length; i++) {
- if (array[i] > array[i + 1]) {
- swaps = true;
- [array[i], array[i + 1]] = [array[i + 1], array[i]]
- }
- }
- }
- return array;
- };
Add Comment
Please, Sign In to add comment