Skip to content

Instantly share code, notes, and snippets.

@DiegoPinho
Last active September 28, 2017 15:46
Show Gist options
  • Save DiegoPinho/a7e9f6f192ecc34e46d03ab34117123f to your computer and use it in GitHub Desktop.
Save DiegoPinho/a7e9f6f192ecc34e46d03ab34117123f to your computer and use it in GitHub Desktop.
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