Skip to content

Instantly share code, notes, and snippets.

@maxdignan
Created July 11, 2015 16:56
Show Gist options
  • Save maxdignan/1967aa893521a4bb269a to your computer and use it in GitHub Desktop.
Save maxdignan/1967aa893521a4bb269a to your computer and use it in GitHub Desktop.
TDD Interview Q 2 CMM
(function tester(func) {
console.log(func([],[]), 'should be []');
console.log(func([1,2],[1,2]), 'should be [1,1,2,2]');
console.log(func([1,2],[1]), 'should be [1,1,2]');
console.log(func(['hi'],[undefined, 'lo']), 'should be [hi,undefined, lo]');
console.log(func([2,3],[]), 'should be [2,3]');
console.log(func([],[2,'und', 5]), 'should be [2,und,3]');
})(function concat(arr1, arr2){
var catted = [];
var iter = 0;
while (iter < arr1.length || iter < arr2.length){
if (iter < arr1.length) {
catted.push(arr1[iter]);
}
if (iter < arr2.length) {
catted.push(arr2[iter]);
}
iter++;
}
return catted
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment