---
id: 69b279bae0f20eda63163cf8
title: Step 14
challengeType: 1
dashedName: step-14
---

# --description--

The `if` and `else` statements you created in the previous steps will assign elements to the sorted array.

Each element assigned to the sorted array takes up an index in the list. So you have to move to the next index in the sorted array after each assignment.

Below the `if`/`else` block, but still within the `while` loop, increment `sortedIndex` by `1`.

# --hints--

You should increment the current value of `sortedIndex` by `1` after your `else` clause.

```js
assert.match(
  __helpers.removeJSComments(mergeSort.toString()),
  /while\s*\(\s*leftArrayIndex\s*<\s*leftPart\.length\s*&&\s*rightArrayIndex\s*<\s*rightPart\.length\s*\)\s*\{[\s\S]*sortedIndex\s*(\+\+|\+=\s*1)\s*;?/
);
```

# --seed--

## --seed-contents--

```js
function mergeSort(array) {
  const middlePoint = Math.floor(array.length / 2);
  const leftPart = array.slice(0, middlePoint);
  const rightPart = array.slice(middlePoint);
  
  mergeSort(leftPart);
  mergeSort(rightPart);
  
  let leftArrayIndex = 0;
  let rightArrayIndex = 0;
  let sortedIndex = 0;

  while (leftArrayIndex < leftPart.length && rightArrayIndex < rightPart.length) {
    if (leftPart[leftArrayIndex] < rightPart[rightArrayIndex]) {
      array[sortedIndex] = leftPart[leftArrayIndex];
      leftArrayIndex += 1;
    } else {
      array[sortedIndex] = rightPart[rightArrayIndex];
      rightArrayIndex += 1;
    }
--fcc-editable-region--
    
--fcc-editable-region--
  }
}
```
