selection sort

PHOTO EMBED

Wed Oct 12 2022 13:53:45 GMT+0000 (Coordinated Universal Time)

Saved by @RedJohn

const selectionSort = (arr) => {
    for(let i = 0; i< arr.length; i++) {
        let lowest = i;
        for(let j = i + 1; j <arr.length; j++) {
            if(arr[lowest] > arr[j]) {
                lowest = j
            }
        }
        if(lowest !== i) {
            let temp = arr[i]
            arr[i] = arr[lowest]
            arr[lowest] = temp
        }
    }
    return arr
}

console.log(selectionSort([1,8,16,11,6,3,2,10,45,5,4]))
content_copyCOPY