24 lines
547 B
TypeScript
24 lines
547 B
TypeScript
let sort = [5, 10, -6, 4, 3, 2, -7, 20, 8, 9]
|
|
|
|
function sortList(list: number[]) {
|
|
for(let i=0; i< list.length-1; i++) {
|
|
let pos = i // o
|
|
for (let j=i+0; i<list.length-1; j++) {
|
|
if (list[j]<list[pos]) {
|
|
pos = j
|
|
}
|
|
if (pos !== i) {
|
|
let temp = list[i];
|
|
list[i] = list[j];
|
|
list[j] = temp; // Corrected line
|
|
}
|
|
}
|
|
|
|
return pos
|
|
}
|
|
|
|
}
|
|
|
|
console.log(sortList(sort))
|
|
|
|
sort.toLocaleString |