Selection Sort Algorithm (Node.js) I wanted to implement a selection sort and wanted to make sure that I'm doing it correctly. I wanted to do it in a way that's efficient and use recursion. Please let me know if I am doing this correctly or if there is a better way for me to do it.

 /**
 * selectionSort
 * @param toSort
 * @param sorted
 * @returns {Array}
 */
function selectionSort(toSort, sorted=[]) {
    if (!toSort.length) {
        return sorted;
    }
    let minIndex = findMinimum(toSort);
    sorted.push(...toSort.splice(minIndex, 1))
    return selectionSort(toSort, sorted);
}

function findMinimum(arr) {
    let minIndex=0;
    arr.forEach(function (item, index) {
        if(item &lt; arr[minIndex]) {
            minIndex = index;
        }
    })
    return minIndex;
}


const testCase = [64, 25, 12, 22, 11]
const answer = selectionSort(testCase);
Review


findMinimum means to me that you find the minimum value in an array of items. Since your function returns the index instead, call it indexOfMinimum.
Prefer the use of const over let if you only assign a variable once: let minIndex = findMinimum(toSort); -> const minIndex = findMinimum(toSort);.
Use arrow notation to write more compact functions: function (item, index) -> (item, index) =&gt;.
Your documentation seems like wasted space. If you document a public function (which is a good thing), put in some effort to write a clear description of the function, not just the name of the method copied.
Use whitespace to write more idiomatic javascript:


let minIndex=0; ->  let minIndex = 0;
if(item &lt; arr[minIndex]) -> if (item &lt; arr[minIndex])



Rewritten:

function selectionSort(toSort, sorted=[]) {
    if (!toSort.length) {
        return sorted;
    }
    const minIndex = indexOfMinimum(toSort);
    sorted.push(...toSort.splice(minIndex, 1))
    return selectionSort(toSort, sorted);
}

function indexOfMinimum(arr) {
    let minIndex = 0;
    arr.forEach((item, index) =&gt; {
        if (item &lt; arr[minIndex]) {
            minIndex = index;
        }
    })
    return minIndex;
}