Code
Diff
  • 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].
    
  • 11
    var merge = function(array1, array2, callbackFN){ 
    
    22
     return callbackFN(array1,array2);
    
    33
    }
    
    44
    55
    function callbackFN(a,b) {
    
    6
      return a.map(function(c,i){return c + b[i];});
    
    6+
      if(Array.isArray(a) && Array.isArray(b) && (a.length === b.length)){
    
    7+
        return a.map(function(c,i){ return c + b[i]; });
    
    8+
      } else {
    
    9+
        return 'both inputs must be Array and same size of elements';
    
    10+
      }
    
    11+
      
    
    77
    }
    
    88
    9
    var x = merge([1, 2, 3, 4], [5, 6, 7, 8], callbackFN);
    
    14+
    var x = merge([1, 3, 4], [5, 6, 7, 8], callbackFN);
    
    1010
    console.log(x);   //x should now equal [6, 8, 10, 12].