function swap(array, i, j) {
    let temp = array[i];
    array[i] = array[j];
    array[j] = temp
}

function indexOfMinimum(array, startIndex) {
    let minValue = array[startIndex];
    let minIndex = startIndex;
    
    for (let i = minIndex + 1; i < array.length; i++) {
        if (array[i] < minValue) {
            minValue = array[i];
            minIndex = i;
        }
    }
    return minIndex;
}

function selectSort(array) {
    for (let i = 0; i < array.length-1; i++) {
        let j = indexOfMinimum(array, i);
        swap(array, i, j);
    }
}

array = [3,5,1,4,2];
console.log(array);
selectSort(array);
console.log(array);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: