@lydiahallie/

GiddyDeadMenus

Nodejs

No description

fork
loading
Files
  • index.js

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6552652069872429","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"ZnVuY3Rpb24gbWVyZ2VTb3J0KGFycmF5KSB7CiAgIGlmIChhcnJheS5sZW5ndGggPT09IDEpIHsKICAgICByZXR1cm4gYXJyYXk7CiAgIH0KICAgY29uc3QgbWlkZGxlID0gTWF0aC5mbG9vcihhcnJheS5sZW5ndGggLyAyKTsKICAgY29uc3QgbGVmdCA9IGFycmF5LnNsaWNlKDAsIG1pZGRsZSk7CiAgIGNvbnN0IHJpZ2h0ID0gYXJyYXkuc2xpY2UobWlkZGxlKTsKICAgcmV0dXJuIG1lcmdlKAogICAgICBtZXJnZVNvcnQobGVmdCksCiAgICAgIG1lcmdlU29ydChyaWdodCkKICAgKTsKfQoKZnVuY3Rpb24gbWVyZ2UobGVmdCwgcmlnaHQpIHsKICBjb25zb2xlLmxvZygnbGVmdCwgcmlnaHQnLCBsZWZ0LCByaWdodCkKICBsZXQgcmVzdWx0ID0gW107CiAgbGV0IGxlZnRJbmRleCA9IDA7CiAgbGV0IHJpZ2h0SW5kZXggPSAwOwoKICB3aGlsZSAobGVmdEluZGV4IDwgbGVmdC5sZW5ndGggJiYgcmlnaHRJbmRleCA8IHJpZ2h0Lmxlbmd0aCkgewogICAgaWYgKGxlZnRbbGVmdEluZGV4XSA8IHJpZ2h0W3JpZ2h0SW5kZXhdKSB7CiAgICAgICByZXN1bHQucHVzaChsZWZ0W2xlZnRJbmRleF0pOwogICAgICAgbGVmdEluZGV4Kys7CiAgICB9IGVsc2UgewogICAgICAgcmVzdWx0LnB1c2gocmlnaHRbcmlnaHRJbmRleF0pOwogICAgICAgcmlnaHRJbmRleCsrOwogICAgfQogIH0KCiAgcmV0dXJuIHJlc3VsdC5jb25jYXQobGVmdC5zbGljZShsZWZ0SW5kZXgpKS5jb25jYXQocmlnaHQuc2xpY2UocmlnaHRJbmRleCkpOwp9CgptZXJnZVNvcnQoWzksIDIsIDMsIDFdKQ=="},"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 mergeSort(array) {
   if (array.length === 1) {
     return array;
   }
   const middle = Math.floor(array.length / 2);
   const left = array.slice(0, middle);
   const right = array.slice(middle);
   return merge(
      mergeSort(left),
      mergeSort(right)
   );
}

function merge(left, right) {
  console.log('left, right', left, right)
  let result = [];
  let leftIndex = 0;
  let rightIndex = 0;

  while (leftIndex < left.length && rightIndex < right.length) {
    if (left[leftIndex] < right[rightIndex]) {
       result.push(left[leftIndex]);
       leftIndex++;
    } else {
       result.push(right[rightIndex]);
       rightIndex++;
    }
  }

  return result.concat(left.slice(leftIndex)).concat(right.slice(rightIndex));
}

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