SOURCE

 const bubble_sort = (list = []) => {
     const len = list.length;

     for(let i = 0; i<len-1; i++) {
         let isExchange = false;
         for(let j = 0; j<len-1-i; j++) {
             if(list[j] > list[j+1]) {
                 isExchange = true;
                 [list[j], list[j+1]] = [list[j+1], list[j]];
             }
         }
         if(!isExchange) return list;
     }

     return list;
 }

 const list = [200, 10, 9, 8, 7,6,4];

 console.log(bubble_sort(list));
console 命令行工具 X clear

                    
>
console