Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. const bubbleSort =(arr)=>{
  2. l = arr.length
  3. for(i=0; i<l; i++){
  4. sort = false
  5. for(j=0; j<l-i-1; j++){
  6. if(arr[j] > arr[j+1]){
  7. temp = arr[j]
  8. arr[j] = arr[j+1]
  9. arr[j+1] = temp
  10. sort = true
  11. }
  12. }
  13. if(sort == false){
  14. break
  15. }
  16. }
  17. return arr
  18. }
  19.  
  20. console.log(bubbleSort([3,2,1,4,5,1025,3]))
  21. console.log(bubbleSort([1,1,1,1,2,4,9,5,555,3,1,1]))
  22. console.log(bubbleSort([0,55,1,3,99,15,0,0]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement