Skip to main content
added 70 characters in body
Source Link

After I played around with splice a little bit more, I was able to refactor out the removeMin function completely. It seems like splice and recursive SelectionSort were made for each other! Of course, some may argue the code has become less readable, or has it really?

function selectRecursive(a) {
    if (!a.length) return []; // terminal case
    minVal = a.splice(findMinIndex(a), 1); // select and remove
    console.log(minVal, a); // to witness the magic of recursion!  
    return minVal.concat(selectRecursive(a)); // concat recursively!
}

After I played around with splice a little bit more, I was able to refactor out the removeMin function completely. It seems like splice and recursive SelectionSort were made for each other! Of course, some may argue the code has become less readable, or has it really?

function selectRecursive(a) {
    if (!a.length) return []; // terminal case
    minVal = a.splice(findMinIndex(a), 1); // select and remove
    return minVal.concat(selectRecursive(a)); // concat recursively!
}

After I played around with splice a little bit more, I was able to refactor out the removeMin function completely. It seems like splice and recursive SelectionSort were made for each other! Of course, some may argue the code has become less readable, or has it really?

function selectRecursive(a) {
    if (!a.length) return []; // terminal case
    minVal = a.splice(findMinIndex(a), 1); // select and remove
    console.log(minVal, a); // to witness the magic of recursion!  
    return minVal.concat(selectRecursive(a)); // concat recursively!
}
Source Link

After I played around with splice a little bit more, I was able to refactor out the removeMin function completely. It seems like splice and recursive SelectionSort were made for each other! Of course, some may argue the code has become less readable, or has it really?

function selectRecursive(a) {
    if (!a.length) return []; // terminal case
    minVal = a.splice(findMinIndex(a), 1); // select and remove
    return minVal.concat(selectRecursive(a)); // concat recursively!
}