javascript selection sort
const selectionSort = array => {
const arr = Array.from(array); // avoid side effects
for (let i = 0; i < arr.length - 1; i++) {
let minPos = i;
for (let j = i + 1; j < arr.length; j++) {
if (arr[j] < arr[minPos]) {
minPos = j;
}
}
if (i !== minPos) {
[arr[i], arr[minPos]] = [arr[minPos], arr[i]];
}
}
return arr;
};
console.log(selectionSort([4, 9, 2, 1, 5]));