Skip to content

Instantly share code, notes, and snippets.

@vacas
Last active April 2, 2017 05:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vacas/08632e36eb9c3acf3739d3acf7997659 to your computer and use it in GitHub Desktop.
Save vacas/08632e36eb9c3acf3739d3acf7997659 to your computer and use it in GitHub Desktop.
Codetrotters Fellowship Exercise 2 - Exercise.a: create on Math.max function from an array of numbers; Exercise.b: create a function that takes 2 array of numbers and outputs the numbers in common
// Exercise a
var arrayofnums = [1,-5,4,-3,2];
function max(array) {
var maxNumber = array[0];
for(var i = 0; i < array.length; i++){
if (array[i] > maxNumber){
maxNumber = array[i];
}
}
console.log(maxNumber);
}
max(arrayofnums);
//Exercise b
var a1 = [1,2,3], a2 = [2,3,4];
function intersection(a1, a2){
var output = [];
a1.map(function(i){
a2.map(function(j){
if(i == j){
output.push(j);
}
})
})
console.log(output);
}
intersection(a1, a2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment