Algorithms - Implement Insertion Sort

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

function insertionSort(array) {
  // Only change code below this line
  for(let i = 1; i < array.length; i++) {
   let x = array[i]
   let j = i

    while(j > 0 && array[j - 1] > x) {
      array[j] = array[j - 1]
      j--
    }

    array[j] = x
  }
  return array;
  // Only change code above this line
}

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.0.0

Challenge: Algorithms - Implement Insertion Sort

Link to the challenge:

hello and welcome to fcc forum :slight_smile:

did you have a question? cause this code is passing just fine for me!!

happy coding :slight_smile:

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