Complete the code to start the outer loop from the second element in the array.
for(let i = [1]; i < arr.length; i++) { // sorting logic }
The insertion sort starts from the second element (index 1) because the first element is considered sorted.
Complete the code to store the current element to be inserted in a variable.
let key = arr[[1]];The variable key holds the element at index i which we want to insert into the sorted part.
Fix the error in the while loop condition to correctly compare elements for insertion.
while(j >= 0 && arr[j] [1] key) { arr[j + 1] = arr[j]; j--; }
The condition arr[j] > key checks if the current element is greater than the key to shift it right.
Fill both blanks to correctly shift elements right.
arr[j [1] 1] = arr[j]; j = j [2] 1;
We shift elements right by assigning to arr[j + 1] and move j left by decrementing it with j - 1.
Fill all three blanks to complete the insertion of the key after shifting elements.
arr[j [1] 1] = [2]; for(let i = [3]; i < arr.length; i++) { // insertion sort logic }
After shifting, we place the key at arr[j + 1]. The outer loop starts from index 1 because the first element is considered sorted.