Advertisement
Guest User

Untitled

a guest
Nov 9th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. function solve() {
  2. let state = ['Water', 'Fire', 'Earth', 'Air'];
  3.  
  4. class Melon {
  5. constructor(weight, melonSort) {
  6. if (new.target === Melon) {
  7. throw new Error(`Abstract class cannot be instantiated directly`);
  8. }
  9. this.weight = weight;
  10. this.melonSort = melonSort;
  11. this._elemIndex = this.weight * this.melonSort.length;
  12. }
  13. get elementIndex() {
  14. return this._elemIndex;
  15. }
  16. toString() {
  17. let a;
  18. if (this instanceof Melolemonmelon) {
  19. a = state[0];
  20. } else {
  21. a = this.constructor.name.split('melon')[0];
  22. }
  23.  
  24. return `Element: ${a}\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex}`;
  25. }
  26. }
  27. class Watermelon extends Melon {
  28. constructor(weight, melonSort) {
  29. super(weight, melonSort);
  30. }
  31. }
  32. class Airmelon extends Melon {
  33. constructor(weight, melonSort) {
  34. super(weight, melonSort);
  35. }
  36. }
  37. class Firemelon extends Melon {
  38. constructor(weight, melonSort) {
  39. super(weight, melonSort);
  40. }
  41. }
  42. class Earthmelon extends Melon {
  43. constructor(weight, melonSort) {
  44. super(weight, melonSort);
  45. }
  46. }
  47.  
  48. class Melolemonmelon extends Watermelon {
  49. constructor(weight, melonSort) {
  50. super(weight, melonSort);
  51. }
  52. morph() {
  53. let changer = state.shift();
  54. state.push(changer);
  55. }
  56. }
  57. return { Melon, Watermelon, Firemelon, Earthmelon, Airmelon, Melolemonmelon };
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement