Skip to content

Instantly share code, notes, and snippets.

@haxiomic
Created September 26, 2014 18:29
Show Gist options
  • Save haxiomic/ecaa020fc47834e4af3c to your computer and use it in GitHub Desktop.
Save haxiomic/ecaa020fc47834e4af3c to your computer and use it in GitHub Desktop.
function orderedMerge(a:Array<Int>, b:Array<Int>){
var result = new Array<Int>();
var ai = 0, bi = 0;
while(ai < a.length || bi < b.length){
var nextA:Null<Int> = ai < a.length ? a[ai] : null;
var nextB:Null<Int> = bi < b.length ? b[bi] : null;
if((nextA < nextB && nextA != null) || nextB == null){
result.push(nextA);
ai++;
}else{
result.push(nextB);
bi++;
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment