const selectionSort = array => {
const {length} = array
for(let i = 0; i < length; i++) {
let minIndex = i
for (let j = i + 1; j < length; j++) {
if (array[j] < array[minIndex]) {
minIndex = j
}
}
if (minIndex !== i) {
[array[i], array[minIndex]] = [array[minIndex], array[i]]
}
}
return array
}
console.log(selectionSort([9, 1, 2, 2, 8, 3, 1, 10, 9, 0, 1, 2]))