// Define a class for the hat store
class HatStore {
constructor() {
this.hats = [];
}
// Method to add a hat to the store
addHat(hat) {
this.hats.push(hat);
}
// Method to remove a hat from the store
removeHat(hat) {
const index = this.hats.indexOf(hat);
if (index !== -1) {
this.hats.splice(index, 1);
}
}
// Method to get all hats in the store
getAllHats() {
return this.hats;
}
}
// Define a class for a hat
class Hat {
constructor(name, price, color) {
this.name = name;
this.price = price;
this.color = color;
}
}
// Create an instance of the hat store
const hatStore = new HatStore();
// Create some hats and add them to the store
const hat1 = new Hat("Baseball Cap", 20, "Black");
const hat2 = new Hat("Beanie", 15, "Blue");
const hat3 = new Hat("Fedora", 30, "Brown");
hatStore.addHat(hat1);
hatStore.addHat(hat2);
hatStore.addHat(hat3);
// Get all hats in the store
const allHats = hatStore.getAllHats();
console.log(allHats);
// Remove a hat from the store
hatStore.removeHat(hat2);
// Get all hats in the store again
const updatedHats = hatStore.getAllHats();
console.log(updatedHats);// your code goes here
Ly8gRGVmaW5lIGEgY2xhc3MgZm9yIHRoZSBoYXQgc3RvcmUKY2xhc3MgSGF0U3RvcmUgewogIGNvbnN0cnVjdG9yKCkgewogICAgdGhpcy5oYXRzID0gW107CiAgfQoKICAvLyBNZXRob2QgdG8gYWRkIGEgaGF0IHRvIHRoZSBzdG9yZQogIGFkZEhhdChoYXQpIHsKICAgIHRoaXMuaGF0cy5wdXNoKGhhdCk7CiAgfQoKICAvLyBNZXRob2QgdG8gcmVtb3ZlIGEgaGF0IGZyb20gdGhlIHN0b3JlCiAgcmVtb3ZlSGF0KGhhdCkgewogICAgY29uc3QgaW5kZXggPSB0aGlzLmhhdHMuaW5kZXhPZihoYXQpOwogICAgaWYgKGluZGV4ICE9PSAtMSkgewogICAgICB0aGlzLmhhdHMuc3BsaWNlKGluZGV4LCAxKTsKICAgIH0KICB9CgogIC8vIE1ldGhvZCB0byBnZXQgYWxsIGhhdHMgaW4gdGhlIHN0b3JlCiAgZ2V0QWxsSGF0cygpIHsKICAgIHJldHVybiB0aGlzLmhh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