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

Tell us what’s happening:

Cannot find a solution on step 35: On each iteration of your while loop, it is finding an element that is larger than your current value. You need to move that element to the right to make room for your current value.

Do so by assigning the value at the j index to the next index:

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) {
  j = j + 1;
  j--;
}

}
}

// User Editable Region


### Your browser information:

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

### Challenge Information:
Learn Basic Algorithmic Thinking by Building a Number Sorter - Step 35
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-basic-algorithmic-thinking-by-building-a-number-sorter/step-35

you have to call the j inside the array as its index
instead of
j = j + 1;
should be
array[j + 1] = array[j];

Thank a lot, worked out

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