-
-
Save eengineergz/61f130c8e0097572ed908fe2629bdee0 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
let selectionSort = (arr) => { | |
let len = arr.length; | |
for (let i = 0; i < len; i++) { | |
let min = i; | |
for (let j = i + 1; j < len; j++) { | |
if (arr[min] > arr[j]) { | |
min = j; | |
} | |
} | |
if (min !== i) { | |
let tmp = arr[i]; | |
arr[i] = arr[min]; | |
arr[min] = tmp; | |
} | |
} | |
return arr; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment