bubbleSort
Sorts an array of numbers, using the bubble sort algorithm.
- Declare a variable,
swapped
, that indicates if any values were swapped during the current iteration. - Use the spread operator (
...
) to clone the original array,arr
. - Use a
for
loop to iterate over the elements of the cloned array, terminating before the last element. - Use a nested
for
loop to iterate over the segment of the array between0
andi
, swapping any adjacent out of order elements and settingswapped
totrue
. - If
swapped
isfalse
after an iteration, no more changes are needed, so the cloned array is returned.