Last active
April 8, 2019 12:45
-
-
Save 4skinSkywalker/f71b17e81bfcb8ecd3c3efb5d32571dd to your computer and use it in GitHub Desktop.
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(array) { | |
| let len = array.length | |
| let b = 1 | |
| while (b < len) { | |
| for (let i = 0; i + b < len; i += b * 2) { | |
| let l = i | |
| let r = i + b | |
| let left = array.slice(l, l+b) | |
| let right = array.slice(r, r+b) | |
| let j = i | |
| for (let item of merge(left, right)) // merge is the function we defined earlier | |
| array[j++] = item | |
| } | |
| b *= 2 | |
| } | |
| return array | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment