The code from the Learn JavaScript the Hard Way module JavaScript Level 1 exercises. This is a mirror of the code I have in the book, so if you're struggling you can use this to compare against your attempts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

31 lines
629 B

let pets = [
{name: 'Yeller', type: 'Dog', age: 12},
{name: 'Akumano', type: 'Japanese Bobtail Cat', age: 2},
{name: 'Meaw Peesard', type: 'Siamese Cat', age: 100},
{name: 'James', type: 'Gecko', age: 2},
]
const young_pets = (pet) => {
return pet.age <= 10;
}
const age_pets = (pet) => {
return [pet.name, pet.age + 10];
}
const name_age = (pet) => {
return `${pet[0]} is ${pet[1]}`;
}
const debug = (msg) => {
console.log(msg);
// why am I doing this here?
return msg;
}
let age_young_animals = pets.filter(young_pets)
.map(age_pets)
.map(debug) // this is why
.map(name_age)
.forEach(debug);