Files
AP-Computer-Principles-Archive/sort.ts
2025-10-27 11:50:13 -05:00

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