Last active
April 2, 2017 05:01
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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