Created
September 26, 2014 18:29
-
-
Save haxiomic/ecaa020fc47834e4af3c 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 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