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]))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter