You are viewing a single comment's thread. Return to all comments →
my solution in JS
function insertionSort1(n, arr) { const lastNum = arr[n - 1] for (let index = n - 2; index >= 0; index--){ let current = arr[index] if (current > lastNum) { arr.splice(arr.indexOf(current)+1, 1, current) console.log(arr.join(' ')) } else if (current < lastNum){ arr.splice(arr.indexOf(current)+1, 1, lastNum) console.log(arr.join(' ')) break; } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Insertion Sort - Part 1
You are viewing a single comment's thread. Return to all comments →
my solution in JS