import { Dog, Cat, PetStore } from './petstore.js';
import { randomPet } from './generator.js';
// 创建一个位于天堂街的宠物店
let petstore = new PetStore('天堂街');
// 创建100个宠物
for (let i = 0; i < 100; i++) {
petstore.add(randomPet());
}
// 统计宠物店狗的数量
let dogs = petstore.fitler(p => p instanceof Dog);
console.log("Number of dogs: " + dogs.length);
console.log(dogs);
// 找出最重的猫
let theCat = petstore.filter(p => p instanceof Cat).reduce((prev, cur) => prev.weight > cur.weight ? prev : cur);
console.log("The big cat: " + theCat);
console.log(theCat);
// 让店里所有的动物都叫一声
petstore.forEach(p => p.bark())
基础题要自己写啊,不动手是不会进步的
不如提问一下那些地方不明白,查缺补漏