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

Tell us what’s happening:

I can’t seem to figure out the issue and have tried everything to fix it. I’m getting the error message “Your while loop should decrement j inside the loop”, but I’m 99% sure I’ve done that correctly. Where’s the error in my code?

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--;
    }
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Challenge Information:

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

Hello, I think you made more than lesson’s request. It is only want to decrement of j at that step :slight_smile: