Created
June 18, 2018 10:50
-
-
Save kaskichandrakant/bece5625a00766fba293fbbc01f91020 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 sort(list) { | |
if (list.length == 1) { | |
return list; | |
} | |
var listA = sort(list.slice(0, list.length / 2)) | |
var listB = sort(list.slice(list.length / 2)) | |
var indexA = 0 | |
var indexB = 0 | |
var newList = [] | |
while (indexA < listA.length || indexB < listB.length) { | |
if (indexA !== listA.length && (listA[indexA] < listB[indexB] || indexB === listB.length)) { | |
newList.push(listA[indexA]); | |
indexA++ | |
} else { | |
newList.push(listB[indexB]); | |
indexB++ | |
} | |
} | |
return newList; | |
} | |
var list = [] | |
for (var i = 0; i < 1000; i++) { | |
let random = Math.floor(Math.random() * 1000) | |
if(!list.includes(random)){ | |
list.push(random) | |
} | |
} | |
console.log(sort(list)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment