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

Tell us what’s happening: When I check my code, I get the error message “Your while loop should decrement j inside the loop.” and I have already tried several ways, can someone guide me?

Your code so far:

while (j >= 0 && array[j] > currValue) {
array[j + 1] = array[j];
j–;
}

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

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

Challenge Information:

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

I think you need to reset the step and add only the decrementing of j

I tried resetting the challenge and adding only j–, and it also asked me to enter the whilw loop
// running tests You should use a

while

loop. Your

while

loop should have its first condition that checks the value of

j

is greater than or equal to

0

. Your

while

loop should use the AND operator. Your

while

loop should have a condition that checks the value of

array[j]

is greater than

currValue

. Your

while

loop should decrement

j

inside the loop. // tests completed

this is my code:
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--;
}

}
}
i can´t find the erro

what is this for? there is no trace in the instructions about this line

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