Skip to content

Instantly share code, notes, and snippets.

@brettbartylla
Created September 9, 2017 22:36
Show Gist options
  • Save brettbartylla/b20b519745a302de7263b72677281cb9 to your computer and use it in GitHub Desktop.
Save brettbartylla/b20b519745a302de7263b72677281cb9 to your computer and use it in GitHub Desktop.
Takes two arrays (obj1, obj3) and merges their values into a new array. The result is the values of obj1 and obj2 but in the order of every other one of their values Ex. a1b2c3
function merge(obj1, obj2){
var obj3 = [];
for (var i= 0, len = obj1.length; i < len; i++) {
obj3.push(obj1[i]);
obj3.push(obj2[i]);
}
return obj3;
}
//calls merge function, removes commas using join, displays output
document.getElementById("answer").innerHTML = merge('abc', '123').join('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment