Thinking:
Comparing each pair of adjacent items and swapping their value (not the index) if they are in the wrong order, then pass through the list from inside to outside until no swaps are needed
let arr = [3,5, 14, 28, 8, 23, 37, 20, 10, 18]
const bubbleSort = (arr) => {
for (let i = 0; i < arr.length - 1; i++) {
for (let j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) { //swap
let temp = arr[j + 1]
arr[j + 1] = arr[j]
arr[j] = temp
}
}
}
return arr
}
console.log(bubbleSort(arr))