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

Tell us what’s happening:

I’m not sure why my code is failing the tests. I feel like I’m following the steps exactly.

Tests:

  1. After your nested for loop, you should declare a temp variable.
  2. You should assign array[i] to temp.
  3. You should assign array[minIndex] to array[i].
  4. You should assign temp to array[minIndex].

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const selectionSort = (array) => {
  for (let i = 0; i < array.length; i++) {
    let minIndex = i;

    for (let j = i + 1; j < array.length; j++) {
      console.log(array, array[j], array[minIndex]);
      if (array[j] < array[minIndex]) {
        minIndex = j;
      }
    }
    let temp;
    temp = array[i];
    array[i] = array[minIndex];
    array[minIndex] = temp;
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.2 Safari/605.1.15

Challenge Information:

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

it doesn’t say so, but it will only pass if use const

1 Like

Thanks! It worked when I changed it to const and combined the temp declaration and assignment into one line. Sometimes fcc can be soo picky.