Created
December 9, 2015 18:38
-
-
Save enrique7mc/7403d8cc7176c9feae2c to your computer and use it in GitHub Desktop.
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
var carros = [ | |
{make: 'Acura', year: 2012}, | |
{make: 'Aston Martin', year: 2010}, | |
{make: 'BMW', year: 2009}, | |
{make: 'Ford', year: 2012}, | |
{make: 'Honda', year: 2015}, | |
{make: 'Jeep', year: 2012}, | |
]; | |
// carros cuya marca tenga longitud mayor a 4 caracteres | |
var consulta1 = carros.filter(function (c) { | |
return c.make.length > 4; | |
}); | |
console.log(consulta1); | |
var consulta1arrow = carros.filter(c => c.make.length > 4); | |
// carros que tengan menos de 5 años | |
var consulta2 = carros.filter(function (c) { | |
return (new Date().getFullYear() - c.year) < 5; | |
}); | |
console.log(consulta2); | |
var consulta2arrow = carros.filter(c => (new Date().getFullYear() - c.year) < 5); | |
// carros mayores a 2010 y cuya marca no comience con 'F' | |
var consulta3 = carros.filter(function (c) { | |
return c.year > 2010 && c.make.charAt(0) !== 'F'; | |
}); | |
console.log(consulta3); | |
var consulta3arrow = carros.filter(c => c.year > 2010 && c.make.charAt(0) !== 'F'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment