Skip to content

Instantly share code, notes, and snippets.

@KamMif
Created July 4, 2018 09:44
Show Gist options
  • Save KamMif/21c3589abd0183b98eb88ee504ec335e to your computer and use it in GitHub Desktop.
Save KamMif/21c3589abd0183b98eb88ee504ec335e to your computer and use it in GitHub Desktop.
// 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