A Pen by Mijanul Karim on CodePen.
Created
August 17, 2019 10:20
-
-
Save mijankarim/1b31e0732812063ed47e418afed105ff to your computer and use it in GitHub Desktop.
Selection Sort JS
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
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