You are viewing a single comment's thread. Return to all comments →
Javascript (ES6). Was used to using arr.sort. It was fun going back to basics.
let ele = arr[n-1]; for(let i = n-2; i >= 0; i--){ if(arr[i] < ele){ arr[i+1] = ele; console.log(...arr); break; } else{ arr[i+1] = arr[i]; console.log(...arr); if (i-1 < 0){ arr[0] = ele; console.log(...arr); } } }
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 →
Javascript (ES6). Was used to using arr.sort. It was fun going back to basics.