-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubblesort.js
More file actions
35 lines (24 loc) · 782 Bytes
/
Copy pathbubblesort.js
File metadata and controls
35 lines (24 loc) · 782 Bytes
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
34
35
function bubbleSort(array, num) {
if (num === undefined){
num = array.length
}
if (num === 1 ){
return array
} else if (num > 1){
for (let i = 0; i < num; i++){
let currentElem = array[i]
let nextElem = array[i+1]
if (currentElem > nextElem){
// console.log('hi')
array[i] = nextElem
array[i+1] = currentElem
}
}
num--
return bubbleSort(array, num)
// return array
} return array
}
// console.log('craziness', array.splice(0, counter, array))
// array = array.splice(0, counter, array)
// return bubbleSort(array)