Write a javascript code of sort array without inbuilt functions
Anónimo
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]) { // Swap elements [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; } } } return arr; } // Example Usage let numbers = [5, 2, 9, 1, 5, 6]; console.log(bubbleSort(numbers)); // Output: [1, 2, 5, 5, 6, 9]