Created
April 4, 2015 11:49
-
-
Save manar007/4a1d446df5a4049952fb to your computer and use it in GitHub Desktop.
Merge sorted arrays
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 mergeArrays(a,b){ | |
var output = [],j,i; | |
for(i = 0; i< a.length; i++){ | |
output.push(a[i]); | |
for(j=0; j< b.length; j++){ | |
if(b[j] <= a[i]){ | |
output.push(b[j]); | |
b.splice(j,1); | |
} | |
} | |
} | |
if(b.length > 0) { | |
output = output.concat(b); | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment