function bubbleSort(arr) {
    let n = arr.length;
    for (let i = 0; i < n-1; i++) {
        for (let j = 0; j < n-i-1; j++) {
            if (arr[j] > arr[j+1]) {
                let temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
    return arr;
}

This implementation of the bubble sort algorithm uses nested loops to repeatedly compare adjacent elements of the input array, and swap them if they are in the wrong order. The outer loop runs for n-1 iterations, where n is the length of the input array, and the inner loop runs for n-i-1 iterations.

Here's an example of how the function can be used:

let arr = [5, 3, 8, 4, 1, 9, -3];
console.log(bubbleSort(arr));  // [-3, 1, 3, 4, 5, 8, 9]