Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Created September 9, 2013 06:42
Show Gist options
  • Save THEtheChad/6492188 to your computer and use it in GitHub Desktop.
Save THEtheChad/6492188 to your computer and use it in GitHub Desktop.
Highly optimized merge for sorted arrays
function mergeSorted(a,b){
var alen = a.length
, blen = b.length
, i, j, k = j = i = 0
, answer = new Array(alen + blen)
;//var
while(i < alen && j < blen)
answer[k++] = a[i] < b[j] ? a[i++] : b[j++];
while(i < alen) answer[k++] = a[i++];
while(j < blen) answer[k++] = b[j++];
return answer;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment