Last active
September 28, 2017 15:46
-
-
Save DiegoPinho/a7e9f6f192ecc34e46d03ab34117123f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var numeros = [1,2,3,4,5]; | |
// forEach | |
numeros.forEach(function(numero){ | |
console.log(numero); | |
}); | |
// map | |
var dobro = numeros.map(function(numero){ | |
return numero * 2 | |
}); | |
console.log(dobro); // 2, 4, 6, 8, 10 | |
// filter | |
var maioresQueTres = numeros.filter(function(numero){ | |
return numero > 3 | |
}); | |
console.log(maioresQueTres); // 4, 5 | |
// find | |
var tres = numeros.find(function(numero){ | |
return numero === 3;m | |
}); | |
console.log(tres); // 3 | |
// every | |
var todosMaiorQueZero = numeros.every(function(numero){ | |
return numero > 0 | |
}); | |
console.log(todosMaiorQueZero); // true | |
// some | |
var algumMaiorQueQuatro = numeros.some(function(numero){ | |
return numero > 4 | |
}); | |
console.log(algumMaiorQueQuatro); // true | |
// reduce | |
var soma = numeros.reduce(function(soma,numero){ | |
return soma + numero; | |
},0) | |
console.log(soma); // 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment