Skip to content

Instantly share code, notes, and snippets.

@mijankarim
Created August 17, 2019 10:20
Show Gist options
  • Save mijankarim/1b31e0732812063ed47e418afed105ff to your computer and use it in GitHub Desktop.
Save mijankarim/1b31e0732812063ed47e418afed105ff to your computer and use it in GitHub Desktop.
Selection Sort JS
const numbers = [99,44,6,2,1,5,63,87,283,4,0];
function selectionSort(array){
const length = array.length;
for( let i = 0; i < length; i++ ){
for( let j = 0; j < length; j++){
if(array[j] > array[j+1]){
let temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}
selectionSort(numbers);
console.log(numbers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment