The current implementation is iterating/looping the length of the array inside the loop. The bubble sort is called bubble sort because in each pass-through, the highest unsorted value “bubbles” up to its correct position. So that those elements can be omitted in the upcoming loop. This new implementation wouldn't go through the whole array every time. Once an element is sorted, it's not considered in the next loop
The current implementation is iterating/looping the length of the array inside the loop. The bubble sort is called bubble sort because in each pass-through, the highest unsorted value “bubbles” up to its correct position. So that those elements can be omitted in the upcoming loop. This new implementation wouldn't go through the whole array every time. Once an element is sorted, it's not considered in the next loop