diff --git a/Sorting Algorithms/bubblesort.js b/Sorting Algorithms/bubblesort.js new file mode 100644 index 00000000..b1799a73 --- /dev/null +++ b/Sorting Algorithms/bubblesort.js @@ -0,0 +1,23 @@ +//function takes in array +const bubblesort = (array) => { + let length = array.length; + + + for (let i=0;i array[j+1]){ + //do the swap + let temp = array[j]; + array[j] = array[j+1]; + array[j+1] = temp; + } + } + } + + return array; +} + +//test array +console.log(bubblesort([3,17,24,4,5,1,4,2,3])); \ No newline at end of file