Ad

#FOR THE SLC JS LEARNERS 2015 STUDY GROUP

Complete the following merge function such that is behaves as described in the example below. Merge should take two arrays of numbers of identical length and a callback function.

var merge = function(array1, array2, callback){  
  //your code here.
}

var x = merge([1, 2, 3, 4], [5, 6, 7, 8], function(a, b){  
  return a + b;
});

//x should now equal [6, 8, 10, 12].

Now, use your merge function to complete the euclid function defined below. Euclid should take two arrays, each of which has an equal number of numerical elements, and return the euclidean distance between them. For a quick refresher on what Euclidean distance is, check here

var euclid = function(coords1, coords2){  
  //Your code here.
  //You should not use any loops and should
  //instead use your original merge function.
}

var y = euclid([1.2, 3.67], [2.0, 4.4]);

//y should now equal approximately 1.08.
var merge = function(array1, array2, callback){  
  var array3 = [];

  if (array1.length !== array2.length) {
    console.log("Array length mismatch");
    return new Error("Array length mismatch");
  } else {
    length = array1.length;
  }

  for (var i = 0; i < length; i++) {
    array3[i] = callback(array1[i], array2[i]);
  }
  return array3;
}

var x = merge([1, 2, 3, 4], [5, 6, 7, 8], function(a, b){  
  return a + b;
});

//x should now equal [6, 8, 10, 12].

var euclid = function(coords1, coords2){  
  //Your code here.
  //You should not use any loops and should
  //instead use your original merge function.
}

var y = euclid([1.2, 3.67], [2.0, 4.4]);

//y should now equal approximately 1.08.
metaseanFailed Tests

Fizz Buzzy

There is a FizzBuzzy Race comming up. There will be a cone dropped at every mile marker divisable by 3 and 5, start at the start line.

When divisable by 3 and 5 there will be two cones dropped.

The start line is the 0th point and needs cones also.

The command will be: 'fizzbuzzy' and take the miles as the sole parameter.

function fizzbuzzy(n) {
  //insert code here
}