YP
Size: a a a
YP
p
const array = [1, 4, 2, 8, 345, 123, 43];
function selectionSort(array) {
let temp = [...array]
for (let i = 0; i < temp.length - 1; i += 1) {
let min = i;
for (let j = i + 1; j < temp.length; j += 1) {
if (temp[min] > temp[j]) min = j;
}
[temp[i], temp[min]] = [temp[min], temp[i]];
}
return temp
}
console.log(selectionSort(array)) //[1,2,4,8,43,123,345]
YP
A
В
YP
YP
p
В
YP
YP
В
p
YP
p
YP
A
YP
A
YP