---
id: 69b279bae0f20eda63163cf2
title: Step 8
challengeType: 1
dashedName: step-8
---

# --description--

Next, you need to create a loop that continues as long as there are elements remaining in both `leftPart` and `rightPart`.

For that, create a `while` loop with two conditions: one that checks whether the `leftArrayIndex` is less than the length of `leftPart` and another condition that checks whether `rightArrayIndex` is less than the length of `rightPart`.

# --hints--

You should create a `while` loop that checks if `leftArrayIndex` is less than the length of `leftPart` and if `rightArrayIndex` is less than the length of `rightPart`.

```js
assert.match(
  __helpers.removeJSComments(code),
  /while\s*\(\s*leftArrayIndex\s*<\s*leftPart\.length\s*&&\s*rightArrayIndex\s*<\s*rightPart\.length\s*\)\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;
  
--fcc-editable-region--
  
--fcc-editable-region--
}
```
