let a = [23, 34, 55, 76, 3, 5, 10];
function bubbleSort(arr) {
const n = arr.length; // Get the length of the array
for (let i = 0; i < n-1; i++) { // Outer loop for each pass
for (let j = 0; j < n-i-1; j++) { // Inner loop for comparisons
if (arr[j] > arr[j+1]) { // If current element is greater than the next
// Swap arr[j] and arr[j+1]
let temp = arr[j]; // Store arr[j] in a temporary variable
arr[j] = arr[j+1]; // Replace arr[j] with arr[j+1]
arr[j+1] = temp; // Replace arr[j+1] with the stored value (temp)
}
}
}
return arr; // Return the sorted array
}
let sortedArray = bubbleSort(a); // Call bubbleSort function to sort the array 'a'
document.write("Sorted array:", sortedArray); // Print the sorted array to the console