Skip to content

Instantly share code, notes, and snippets.

@Bouzazi
Created June 24, 2019 14:16
Show Gist options
  • Save Bouzazi/d385f1b0902081d9f0bcea27d26eb52d to your computer and use it in GitHub Desktop.
Save Bouzazi/d385f1b0902081d9f0bcea27d26eb52d to your computer and use it in GitHub Desktop.
ES6 Checkpoint
var pets = [
{ name: "Max", type: "dog", bornOn: 2018 },
{ name: "Angel", type: "cat", bornOn: 2015 },
{ name: "Jasper", type: "dog", bornOn: 2016 }
];
const getAge = pet => {
return new Date().getFullYear() - pet.bornOn;
}
let petsWithAge = [];
pets.forEach( (pet) => {
pet.age = getAge(pet);
petsWithAge.push(pet);
});
console.log(petsWithAge);
let dogs = [];
pets.forEach( (pet) => {
if (pet.type == "dog"){
dogs.push(pet);
}
});
console.log(dogs);
let jasper;
pets.forEach( (pet) => {
if (pet.name === "Jasper"){
jasper = pet;
}
});
console.log(`Jasper is ${jasper.age} years old`);
@amine371
Copy link

es6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment