Created
August 12, 2021 11:49
-
-
Save carlosrojaso/2ce0d6a469d338404ad7b27fdb2b43cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//Equipment | |
class Equipment { | |
getPrice() { | |
return this.price || 0; | |
} | |
getName() { | |
return this.name; | |
} | |
setName(name) { | |
this.name = name; | |
} | |
} | |
class Pattern extends Equipment { | |
constructor() { | |
super(); | |
this.equipments = []; | |
} | |
add(equipment) { | |
this.equipments.push(equipment); | |
} | |
getPrice() { | |
return this.equipments | |
.map(equipment => { | |
return equipment.getPrice(); | |
}) | |
.reduce((a, b) => { | |
return a + b; | |
}); | |
} | |
} | |
class Cabbinet extends Pattern { | |
constructor() { | |
super(); | |
this.setName('cabbinet'); | |
} | |
} | |
// --- leafs --- | |
class FloppyDisk extends Equipment { | |
constructor() { | |
super(); | |
this.setName('Floppy Disk'); | |
this.price = 70; | |
} | |
} | |
class HardDrive extends Equipment { | |
constructor() { | |
super(); | |
this.setName('Hard Drive'); | |
this.price = 250; | |
} | |
} | |
class Memory extends Equipment { | |
constructor() { | |
super(); | |
this.setName('Memory'); | |
this.price = 280; | |
} | |
} | |
export { Cabbinet, FloppyDisk, HardDrive, Memory }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment