---
id: 69b279bae0f20eda63163d02
title: Step 24
challengeType: 1
dashedName: step-24
---

# --description--

After logging the unsorted array, call the `mergeSort` function and pass in the `numbers` array as an argument.

# --hints--

You should call `mergeSort(numbers)` after logging the unsorted array.

```js
assert.match(
  __helpers.removeJSComments(code),
  /console\.log\s*\(\s*['"]Unsorted array:\s*['"]\s*\)\s*;?\s*console\.log\s*\(\s*numbers\s*\)\s*;?\s*mergeSort\s*\(\s*numbers\s*\)\s*;?/
);
```

# --seed--

## --seed-contents--

```js
function mergeSort(array) {
  if (array.length <= 1) {
    return;
  }

  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;
    }
    sortedIndex += 1;
  }

  while (leftArrayIndex < leftPart.length) {
    array[sortedIndex] = leftPart[leftArrayIndex];
    leftArrayIndex += 1;
    sortedIndex += 1;
  }
  
  while (rightArrayIndex < rightPart.length) {
    array[sortedIndex] = rightPart[rightArrayIndex];
    rightArrayIndex += 1;
    sortedIndex += 1;
  }
}

const numbers = [4, 10, 6, 14, 2, 1, 8, 5];
console.log('Unsorted array: ');
console.log(numbers);
--fcc-editable-region--

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