Created
May 21, 2019 17:21
-
-
Save Ikhan/cf27e3074814f660d4cfb1482e33830e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function selectionSort(arr) { | |
for (let i=0; i < arr.length; i++) { | |
let lowest = i; | |
for(let j = i+1; j < arr.length; j++) { | |
if (arr[j] < arr[lowest]) { | |
lowest = j; | |
} | |
} | |
if (i !== lowest) { | |
let temp = arr[i]; | |
arr[i] = arr[lowest]; | |
arr[lowest] = temp; | |
} | |
} | |
return arr; | |
} | |
selectionSort([3,10,11,8,1,2,6,9]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment