function bubbleSort(array) { let swapped = true; while (swapped) { swapped = false; for (let i = 1; i < array.length; i++) { if (array[i] < array[i-1]) { let temp = array[i-1]; array[i-1] = array[i]; array[i] = temp; swapped = true; } } } return array; } function selectionSort(array) { for (let i = 0; i < array.length - 1; i++) { let smallest = i; for (let j = i+1; j < array.length; j++) { if (array[smallest] > array[j]) { smallest = j; } } let temp = array[smallest]; array[smallest] = array[i]; array[i] = temp; } return array; } const notSortedArray = [32, 34, 244, 7, 45, 57, 234, 5, 90, 35, 3546, 567, 32]; selectionSort(notSortedArray); bubbleSort(notSortedArray); const arrayOf1000Selection = Array.from({ length: 20000 }, () => Math.floor(Math.random() * 80)).sort((a, b) => a - b); const arrayOf1000Bubble = arrayOf1000Selection.slice(); console.time('bubble'); const sortedB = bubbleSort(arrayOf1000Bubble); console.timeEnd('bubble'); console.time('selection'); const sortedS = selectionSort(arrayOf1000Selection); console.timeEnd('selection');