Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var pets = [
- {name:"rover",animal:"dog",amount:27},
- {name:"freddy",animal:"turtle",amount:27},
- {name:"deefor",animal:"dog",amount:27},
- {name:"sir barkalot",animal:"dog",amount:27},
- {name:"cedric",animal:"snake",amount:27}
- ]
- // var dogs = pets.filter(function(pets) {
- // return pets.animal == "dog"
- // })
- const dogs = pets.filter((e) => e.animal === "dog")
- // var names = pets.map(function(p) { return p.name});
- const names = pets.map((p) => p.name);
- // var total = pets.reduce(function(sum,pet) {
- // console.log("inside reduce : ", sum, pet)
- // return sum + pet.amount
- // },0)
- const total = pets.reduce((sum ,pet) => sum + pet.amount, 0)
- console.log(total);
- console.log(dogs);
- console.log(names);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement