Skip to content

Instantly share code, notes, and snippets.

@4skinSkywalker
Last active April 8, 2019 12:45
Show Gist options
  • Select an option

  • Save 4skinSkywalker/489ae5fe53b029be2c4e5cbf309a27dc to your computer and use it in GitHub Desktop.

Select an option

Save 4skinSkywalker/489ae5fe53b029be2c4e5cbf309a27dc to your computer and use it in GitHub Desktop.
function mergeSort(array) {
let n = array.length
if (n === 1) {
return array
}
let left = array.slice(0, Math.floor(n/2))
let right = array.slice(Math.floor(n/2))
return merge( mergeSort(left), mergeSort(right) ) // merge is the function we defined earlier
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment