diff --git a/bubble Sort b/bubble Sort new file mode 100644 index 000000000..45f06ab63 --- /dev/null +++ b/bubble Sort @@ -0,0 +1,23 @@ +function bubbleSort(arr) { + const n = arr.length; + + + for (let i = 0; i < n - 1; i++) { + + for (let j = 0; j < n - i - 1; j++) { + + if (arr[j] > arr[j + 1]) { + + const temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } + return arr; +} + + +const array = [64, 34, 25, 12, 22, 11, 90]; +const sortedArray = bubbleSort(array); +console.log('Sorted Array:', sortedArray);