@lydiahallie/

OpaqueStupidAddition

Nodejs

No description

fork
loading
Files
  • index.js

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6033169133052403","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"ZnVuY3Rpb24gcXVpY2tzb3J0KGFycmF5LCBsZWZ0LCByaWdodCkgewogICBsZWZ0ID0gbGVmdCB8fCAwOwogICByaWdodCA9IHJpZ2h0IHx8IGFycmF5Lmxlbmd0aCAtIDE7CiAgCiAgIGNvbnN0IHBpdm90ID0gcGFydGl0aW9uSG9hcmUoYXJyYXksIGxlZnQsIHJpZ2h0KTsKICAgCiAgIGlmIChsZWZ0IDwgcGl2b3QgLSAxKSB7CiAgICAgIHF1aWNrc29ydChhcnJheSwgbGVmdCwgcGl2b3QgLSAxKTsKICAgfQogICBpZiAocmlnaHQgPiBwaXZvdCkgewogICAgICBxdWlja3NvcnQoYXJyYXksIHBpdm90LCByaWdodCk7CiAgIH0KICAgcmV0dXJuIGFycmF5Owp9CgpmdW5jdGlvbiBwYXJ0aXRpb25Ib2FyZShhcnJheSwgbGVmdCwgcmlnaHQpIHsKICAgY29uc3QgcGl2b3QgPSBNYXRoLmZsb29yKE1hdGgucmFuZG9tKCkgKiAocmlnaHQgLSBsZWZ0ICsgMSkgKyBsZWZ0KTsKICAgd2hpbGUgKGxlZnQgPD0gcmlnaHQpIHsKICAgICB3aGlsZSAoYXJyYXlbbGVmdF0gPCBhcnJheVtwaXZvdF0pIHsgIAogICAgICAgIGxlZnQrKzsKICAgICB9ICAKICAgICB3aGlsZSAoYXJyYXlbcmlnaHRdID4gYXJyYXlbcGl2b3RdKSB7CiAgICAgICByaWdodC0tOwogICAgIH0KICAgICBpZiAobGVmdCA8PSByaWdodCkgewogICAgICAgW2FycmF5W2xlZnRdLCBhcnJheVtyaWdodF1dID0gW2FycmF5W3JpZ2h0XSwgYXJyYXlbbGVmdF1dOwogICAgIH0KICAgfQogICByZXR1cm4gbGVmdDsKfQoKcGFydGl0aW9uSG9hcmUoWzksIDUsIDMsIDEsIDJdLCA5LCAyKQo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function quicksort(array, left, right) {
   left = left || 0;
   right = right || array.length - 1;
  
   const pivot = partitionHoare(array, left, right);
   
   if (left < pivot - 1) {
      quicksort(array, left, pivot - 1);
   }
   if (right > pivot) {
      quicksort(array, pivot, right);
   }
   return array;
}

function partitionHoare(array, left, right) {
   const pivot = Math.floor(Math.random() * (right - left + 1) + left);
   while (left <= right) {
     while (array[left] < array[pivot]) {  
        left++;
     }  
     while (array[right] > array[pivot]) {
       right--;
     }
     if (left <= right) {
       [array[left], array[right]] = [array[right], array[left]];
     }
   }
   return left;
}

partitionHoare([9, 5, 3, 1, 2], 9, 2)
node v10.16.0