Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bubbleSort(arr) {
- const sortedArray = [...arr];
- for(let i = sortedArray.length - 1; i >= 0; i--) {
- for(let j = 0; j < i; j++) {
- if (sortedArray[j] > sortedArray[j + 1]) {
- [sortedArray[j], sortedArray[j + 1]] = [sortedArray[j + 1], sortedArray[j + 1]];
- }
- }
- }
- return sortedArray;
- }
- console.log(bubbleSort([1,4,2,11,3, 33,21]));
Add Comment
Please, Sign In to add comment