function biggest(array, index) { let biggest = array[index]; let ind = index; for (let i = index; i < array.length; i++) { if (array[i] > biggest) { biggest = array[i]; ind = i; } } return ind; } function theRealSelectionSort(array, selector) { let startIndex = 0; while (startIndex < array.length) { const biggest = selector(array, startIndex); array.unshift(array.splice(biggest, 1)[0]); startIndex += 1; } return array; } const notSortedArray = [32, 34, 244, 7, 45, 57, 234, 5, 90, 35, 3546, 567, 32]; const sorted = theRealSelectionSort(notSortedArray, biggest); console.log(sorted);