Created
January 30, 2017 03:38
-
-
Save danielsharvey/6013d4c41b8b934fb67c447358017b5f to your computer and use it in GitHub Desktop.
Javascript merge function
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 merge(left, right, sortFieldName){ | |
var ret = [] | |
var il = 0 | |
var ir = 0 | |
while (il < left.length && ir < right.length) { | |
if (left[il][sortFieldName].valueOf() < right[ir][sortFieldName].valueOf()) { | |
ret.push(left[il++]) | |
} else { | |
ret.push(right[ir++]) | |
} | |
} | |
while(il<left.length) ret.push(left[il++]) | |
while(ir<right.length) ret.push(right[ir++]) | |
return ret // ret.concat(left.slice(il)).concat(right.slice(ir)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment