bubble sort

Run Settings
LanguageJavaScript
Language Version
Run Command
function bubbleSort(arr) { let sorted; do { sorted = true; for (let i = 0; i < arr.length - 1; i++) { console.log(...arr); console.log(' '.repeat(i) + '^ ^'); if (arr[i] > arr[i + 1]) { sorted = false; [arr[i], arr[i + 1]] = [arr[i + 1], arr[i]]; } } } while (!sorted); } bubbleSort([1, 3, 2, 5, 4, 8, 9, 7, 6, 0]);
Editor Settings
Theme
Key bindings
Full width
Lines