Last active
August 16, 2019 15:41
-
-
Save Tlaloc-Es/153ad2e7dd93c0010bf8905a470b29cd to your computer and use it in GitHub Desktop.
This file contains 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(list){ | |
if(list.length > 1){ | |
let middle = list.length/2 | |
return merge(mergesort(list.slice(0, middle)), mergesort(list.slice(middle, list.length))) | |
}else{ | |
return list | |
} | |
} | |
function merge(listA, listB){ | |
if(listA.length === 0){return listB} | |
if(listB.length === 0){return listA} | |
if(listA[0] < listB[0]){ | |
return [listA[0]].concat(merge(listA.slice(1, listA.length), listB)) | |
}else{ | |
return [listB[0]].concat(merge(listA, listB.slice(1, listB.length))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment