Created
November 30, 2010 18:12
-
-
Save pheuter/722102 to your computer and use it in GitHub Desktop.
Javascript implementation of merge assignment
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
// ~ 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