Selection Sort

Run Settings
LanguageJavaScript
Language Version
Run Command
const numbers = [3,11,2,5,3,9,7,5,3]; const selectionSort = arr => { let smallest_index = 0; for(let i=0; i<arr.length; i++) { for(let j=i; j<arr.length; j++) { if(arr[j] < arr[smallest_index]) smallest_index = j; } [ arr[i], arr[smallest_index] ] = [ arr[smallest_index], arr[i] ]; } } selectionSort(numbers); console.log(numbers);
Editor Settings
Theme
Key bindings
Full width
Lines