---
id: 69b279bae0f20eda63163cf1
title: Step 7
challengeType: 1
dashedName: step-7
---

# --description--

Now it's time to sort and merge the lists (`leftPart` and `rightPart`) into the original `array`. 

You can do this by comparing elements on both lists, and merging the smaller element to the main list. You are going to do this comparison for all the indexes in `leftPart` and `rightPart`.

Create three variables: `leftArrayIndex`, `rightArrayIndex`, and `sortedIndex`, and set their values to `0`. These variables will help you keep track of each index during the sorting process.

# --hints--

You should declare a `leftArrayIndex` variable initialized to `0`.

```js
assert.match(
  __helpers.removeJSComments(mergeSort.toString()),
  /(let|const|var)\s+leftArrayIndex\s*=\s*0\s*;?/
);
```

You should declare a `rightArrayIndex` variable initialized to `0`.

```js
assert.match(
  __helpers.removeJSComments(mergeSort.toString()),
  /(let|const|var)\s+rightArrayIndex\s*=\s*0\s*;?/
);
```

You should declare a `sortedIndex` variable initialized to `0`.

```js
assert.match(
  __helpers.removeJSComments(mergeSort.toString()),
  /(let|const|var)\s+sortedIndex\s*=\s*0\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);

--fcc-editable-region--
  
--fcc-editable-region--
}
```
