var merge = function(array1, array2, callbackFN){ return callbackFN(array1,array2); } function callbackFN(a,b) { if(Array.isArray(a) && Array.isArray(b) && (a.length === b.length)){ return a.map(function(c,i){ return c + b[i]; }); } else { return 'both inputs must be Array and same size of elements'; } } var x = merge([1, 3, 4], [5, 6, 7, 8], callbackFN); console.log(x); //x should now equal [6, 8, 10, 12].
- var merge = function(array1, array2, callbackFN){
- return callbackFN(array1,array2);
- }
- function callbackFN(a,b) {
return a.map(function(c,i){return c + b[i];});- if(Array.isArray(a) && Array.isArray(b) && (a.length === b.length)){
- return a.map(function(c,i){ return c + b[i]; });
- } else {
- return 'both inputs must be Array and same size of elements';
- }
- }
var x = merge([1, 2, 3, 4], [5, 6, 7, 8], callbackFN);- var x = merge([1, 3, 4], [5, 6, 7, 8], callbackFN);
- console.log(x); //x should now equal [6, 8, 10, 12].