Implementation of JavaScript merge() function


Took 4 minutes 9 seconds to implement JavaScript merge() function for same length arrays. Here is the code snippet.

Function:

arr1 = ['bla', 'bla', 'bla'];
arr2 = ['ha', 'ha', 'ha'];
function merge(arr1, arr2) {
for (var i = 0; i < arr2.length; i++) {
arr1.push(arr2[i]);
}
}

merge(arr1, arr2);
document.write(arr1)

Result:

bla,bla,bla,ha,ha,ha

No comments:

Post a Comment

Coding for Kids

What is coding? In coding we build a program to do a specific task for us. Code: A code is a set of computer instructions and when you will ...