Created
July 2, 2019 14:38
-
-
Save verdi327/a2ad4c72de30c03f84260633da5b9b9a to your computer and use it in GitHub Desktop.
merge-sort.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mergeSort(arr) { | |
if (arr.length <= 1) { | |
return arr; | |
} | |
let middle = Math.floor(arr.length/2); | |
let left = mergeSort(arr.slice(0, middle)); | |
let right = mergeSort(arr.slice(middle)); | |
return merge(left, right); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment