Created
July 2, 2018 18:42
-
-
Save vitorpiovezam/4b8d01d16e5f6557c8e10754ca627818 to your computer and use it in GitHub Desktop.
pegando argumentos como array
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
function arraySum(arr1, arr2){ | |
var idades = arguments; | |
var diferencaTemp; | |
var mediaDiferenca = 0; | |
if(arguments[0].length == arguments[1].length){ | |
for(i in arguments[0]){ | |
diferencaTemp = (arguments[1][i] - arguments[0][i]); | |
//console.log("Age difference in " + diferencaTemp); | |
mediaDiferenca += diferencaTemp; | |
} | |
mediaDiferenca = mediaDiferenca/(arguments[0].length); | |
console.log(mediaDiferenca); | |
}else{ | |
console.log("Os arrays são de tamanhos diferentes"); | |
console.log("Numero de idades do array 1 -> " + arguments[0].length); | |
console.log("Numero de idades do array 2 -> " + arguments[1].length); | |
} | |
} | |
var idadeFilhos = [13,19,4,10,5,2,9,23,15,2,1,2,14,12,18,1,6,12,4,6,19,17,17]; | |
var idadePais = [33,43,27,32,30,28,29,23,56,43,32,30,24,42,43,32,23,17,19,23,27,56,45]; | |
try{ | |
arraySum(idadeFilhos, idadePais); | |
}catch(Exc){ | |
console.log(Exc) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment