Learn Basic Algorithmic Thinking by Building a Number Sorter - Step 34

the error is that I should decrement j inside the while loop that’s what am doing

Your code so far

const insertionSort = (array) => {
  for (let i = 1; i < array.length; i++) {
    const currValue = array[i];
    let j = i - 1;
    while(j >= 0 && array[j] > currValue){
      array[j + 1] = array[j];
      j--;
    }
  }
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Learn Basic Algorithmic Thinking by Building a Number Sorter - Step 34

The problem is the assignment inside your while loop, you don’t need it (yet). Just decrement j for now.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.