BubbleSort

Run Settings
LanguageJavaScript
Language Version
Run Command
const bubbleSort = (arr)=>{ let time = Date.now(); for(let i = 0;i<arr.length;i++) { for(let j = i+1;j<arr.length;j++) { if(arr[i]>arr[j]) { let temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } let after_time = Date.now(); console.log(`time taken = ${(after_time-time)/1000} seconds`) return arr; } let array = Array.from({length: 100000},(x,i)=>Math.floor(Math.random()*i)); console.log(bubbleSort(array))
Editor Settings
Theme
Key bindings
Full width
Lines