Created
June 24, 2019 14:16
-
-
Save Bouzazi/d385f1b0902081d9f0bcea27d26eb52d to your computer and use it in GitHub Desktop.
ES6 Checkpoint
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 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`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
es6