Skip to content

Instantly share code, notes, and snippets.

@manar007
Created April 4, 2015 11:49
Show Gist options
  • Save manar007/4a1d446df5a4049952fb to your computer and use it in GitHub Desktop.
Save manar007/4a1d446df5a4049952fb to your computer and use it in GitHub Desktop.
Merge sorted arrays
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