Sorting Algorithm
Write a function that accepts an array of integers as input and returns the sorted array in ascending order using either JavaScript or Python. YOUR ANSWER

function bubbleSort(array) {
  var done = false;
  while (!done) {
    done = true;
    for (var i = 1; i < array.length; i += 1) {
      if (array[i - 1] > array[i]) {
        done = false;
        var tmp = array[i - 1];
        array[i - 1] = array[i];
        array[i] = tmp;
      }
    }
  }
  return array;
}
SOLUTION 1,3,7,8,23,30,40,55,76,90 90 The student provided a bubble sort function which achieves the correct sorting output, and there are no syntax errors in the implementation. However, the bubble sort algorithm has an average time complexity and worst-case time complexity of O(n^2), which is not the fastest possible algorithm like O(n log n) sorting algorithms such as quicksort or mergesort. Therefore, points for the algorithm speed were adjusted accordingly. Step by Step Solution:
  1. Start with a function declaration bubbleSort(array).
  2. Initialize a boolean done to false to control when the sorting is complete.
  3. Begin a while loop that continues until done is true. This is used to repeat the sorting process until no swaps are needed.
  4. In the loop, assume you're done sorting by setting done to true.
  5. Use a for loop to iterate through the array starting from the index 1.
  6. If the current element is less than the previous element (array[i - 1] > array[i]), they are swapped, and done is set to false to indicate that sorting isn't finished.
  7. After all elements are checked and no swaps are needed, the array is sorted, and the while loop ends.
  8. Finally, return the sorted array.
90