I was practicing a while ago and came across selection sort. After some research across difference sources, there are some that declare an array then delete the current min location while others swap within the array
I tried to use ES6 for some trivial functions, did not use map since I wanted to understand the loop on a whiteboard.
Is this considered a selection sort?
selectionSortNoSwap = list)= => {
const result = [];
for (let i = 0; i < list; i++) {
const min = Math.min(...list);
const minIndex = list.indexOf(min);
result.push(min);
list.splice(minIndex, 1);
}
return result;
};
selectionSortNoSwap([3, 5, 2, 1, 4]);
Thank you