Guest User

Untitled

a guest
Dec 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. function bubbleSort(arr) {
  2. const sortedArray = [...arr];
  3.  
  4. for(let i = sortedArray.length - 1; i >= 0; i--) {
  5. for(let j = 0; j < i; j++) {
  6. if (sortedArray[j] > sortedArray[j + 1]) {
  7. [sortedArray[j], sortedArray[j + 1]] = [sortedArray[j + 1], sortedArray[j + 1]];
  8. }
  9. }
  10. }
  11.  
  12. return sortedArray;
  13. }
  14.  
  15. console.log(bubbleSort([1,4,2,11,3, 33,21]));
Add Comment
Please, Sign In to add comment