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:
- After your nested for loop, you should declare a temp variable.
- You should assign array[i] to temp.
- You should assign array[minIndex] to array[i].
- 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