scwebd
1/31/2019 - 6:01 AM

Insert Sort Algorithm

function insertionSort(items) {
    // loop through the items array, using 'i'

        // preserve the value at index 'i' -- you'll insert it later at the correct index

        // now, loop *backwards* through the SORTED part of the array, using 'j' (hint: start at index
        // 'i - 1'), and comparing each value in the loop to the value preserved above... keep looping 
        // so long as the value at index 'j' is greater than the preserved value
        
            // shift each value one slot to the right (to make room for inserting the preserved value)

        // when we exit the 'j' loop, that means we've found the slot where we want to
        // insert the preserved value!

    // when we finally emerge from the outer loop, that means all numbers should be sorted!
}