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

GITEX Dubai Talk by Saion Gupta and Saiasmi Gupta

Good morning, everyone. I'm Saion Gupta, the Founder of 10xCoderKids and the Guinness World Record holder for the youngest computer prog...