Files
AP-Computer-Principles-Archive/sort.js
2025-10-27 11:49:47 -05:00

20 lines
492 B
JavaScript

let sort = [5, 10, -6, 4, 3, 2, -7, 20, 8, 9]
function sortList(list) {
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
}
}
}
}
console.log(sortList(sort))