Write a function that sorts a given array using the Bubble Sort Algorithm and returns the sorted Array. For eg.
bubbleSort([1,5,3,0])
should return [0,1,3,5]
bubbleSort([-1,0,-5,5,8])
should return [-5,-1,0,5,8]
function bubbleSort(arr){
// write your code here
}
console.log(bubbleSort([1,5,3,0])); // should return `[0,1,3,5]`
console.log(bubbleSort([-1,0,-5,5,8])); // should return `[-5,-1,0,5,8]`
Note: You must use break
keyword to break out of the loop if there is no swap happening in current iteration.