@lydiahallie/

OptimisticPastAbility

Nodejs

No description

fork
loading
Files
  • index.js

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.7870653753418586","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"CmZ1bmN0aW9uIGJ1YmJsZVNvcnQoYXJyYXkpIHsKICBsZXQgc3dpdGNoZWQKICBkbyB7CiAgICBzd2l0Y2hlZCA9IGZhbHNlCiAgICBmb3IgKGxldCBpID0gMDsgaSA8IGFycmF5Lmxlbmd0aDsgaSsrKSB7CiAgICAgIGlmIChhcnJheVtpXSA+IGFycmF5W2kgKyAxXSkgewogICAgICAgIFthcnJheVtpXSwgYXJyYXlbaSArIDFdXSA9IFthcnJheVtpICsgMV0sIGFycmF5W2ldXQogICAgICAgIHN3aXRjaGVkID0gdHJ1ZQogICAgICB9CiAgICB9CiAgfSB3aGlsZShzd2l0Y2hlZCkKICByZXR1cm4gYXJyYXkKfQoKYnViYmxlU29ydChbOSwgNSwgMTAsIDMsIDJdKSAvLyBbMiwgMywgNSwgOSwgMTBdCgovLyBCZXN0IHRpbWU6IE8obikuIAovLyBBdmVyYWdlIGFuZCB3b3JzdCB0aW1lOiBPKG4gXiAyKS4gCi8vIFNwYWNlOiBPKDEpLiBPKG4pLiA="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function bubbleSort(array) {
  let switched
  do {
    switched = false
    for (let i = 0; i < array.length; i++) {
      if (array[i] > array[i + 1]) {
        [array[i], array[i + 1]] = [array[i + 1], array[i]]
        switched = true
      }
    }
  } while(switched)
  return array
}

bubbleSort([9, 5, 10, 3, 2]) // [2, 3, 5, 9, 10]

// Best time: O(n). 
// Average and worst time: O(n ^ 2). 
// Space: O(1). O(n). 
node v10.16.0