SOURCE

function topK(arr,k){
    quickSort(arr,0,arr.length-1)
}   

function quickSort(arr,l,r){
   if(l>=r) return;
   let i = l,j = r;
   while(i<j){
       while(arr[j] >= arr[l]) j--;
       while(arr[i] <= arr[l]) i++;
       swap(arr,i,j);
   }
   swap(arr,i,l);

   quickSort(arr,l,i-1);
   quickSort(arr,i+1,r)
}

function swap(arr,i,j){
    let temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
}
console 命令行工具 X clear

                    
>
console