Created
July 4, 2018 09:44
-
-
Save KamMif/21c3589abd0183b98eb88ee504ec335e 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 for rinding min index of elemtnt in array | |
function smallest(arr) { | |
let smallest[0]; | |
let smallestIndex = 0; | |
for (let i = 0; i < arr.length; i ++) { | |
if (arr[i] < smallest) { | |
smallest = arr[i] | |
smallestIndex = i | |
} | |
} | |
return smallestIndex; | |
} | |
// Function for selected sorting | |
function selectionSort(arr) { | |
let newArr = []; | |
const length = arr.length; | |
for (let j = 0; j < length; j++) { | |
let smallestIndex = smallest(arr); | |
newArr.push(+arr.splice(smallestIndex, 1).join('')) | |
} | |
return newArr; | |
} | |
console.log(selectionSort([5,3,6,2,10])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment