Skip to content

Instantly share code, notes, and snippets.

@pheuter
Created November 30, 2010 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pheuter/722102 to your computer and use it in GitHub Desktop.
Save pheuter/722102 to your computer and use it in GitHub Desktop.
Javascript implementation of merge assignment
// ~ 3 loc
var puts = require('sys').puts;
function merge (a1, a2) {
var merged = [];
while(a1 && a2 != '') merged.push(a1[0] <= a2[0] ? a1.shift() : a2.shift());
return merged.concat(a1 != '' ? a1 : a2);
}
puts(merge([1,3,5,7,9],[2,4,6,8,10]));
// 1,2,3,4,5,6,7,8,9,10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment