Advertisement
Guest User

Melons

a guest
Nov 8th, 2016
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. // Единия тест мина след, като написах по друг начин "morph" метода,
  2. // другия след, като оправих индекса за елементите, които взимат типовете от "arrayMelon" масива
  3. // и направих във "toString" всички "Element index" да са "Element Index"
  4.  
  5. function solve() {
  6. class Melon {
  7. constructor(weight,melonSort) {
  8. if (new.target === Melon) {
  9. throw new TypeError("Abstract class cannot be instantiated directly");
  10. }
  11. this._weight = weight;
  12. this._melonSort = melonSort;
  13. this.arrayMelon = ["Water","Fire","Earth","Air"];
  14. }
  15. get weight() {
  16. return this._weight;
  17. }
  18. get melonSort() {
  19. return this._melonSort;
  20. }
  21. toString() {
  22. return `Sort: ${this.melonSort}\n`;
  23. }
  24. }
  25.  
  26. class Watermelon extends Melon {
  27. constructor(weight,melonSort) {
  28. super(weight,melonSort);
  29. }
  30. get elementIndex() {
  31. return this.weight * this.melonSort.length;
  32. }
  33. toString() {
  34. return `Element: ${this.arrayMelon[0]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
  35. }
  36. }
  37.  
  38. class Firemelon extends Melon{
  39. constructor(weight,melonSort) {
  40. super(weight,melonSort);
  41. }
  42. get elementIndex() {
  43. return this.weight * this.melonSort.length;
  44. }
  45. toString() {
  46. return `Element: ${this.arrayMelon[1]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
  47. }
  48. }
  49. class Earthmelon extends Melon{
  50. constructor(weight,melonSort) {
  51. super(weight,melonSort);
  52. }
  53. get elementIndex() {
  54. return this.weight * this.melonSort.length;
  55. }
  56. toString() {
  57. return `Element: ${this.arrayMelon[2]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
  58. }
  59. }
  60. class Airmelon extends Melon {
  61. constructor(weight,melonSort) {
  62. super(weight,melonSort);
  63. }
  64. get elementIndex() {
  65. return this.weight * this.melonSort.length;
  66. }
  67. toString() {
  68. // Вместо this.arrayMelon[3] беше написано от 2 - ри индекс
  69. return `Element: ${this.arrayMelon[3]}\n`+ super.toString() + `Element Index: ${this.elementIndex}`; // Idex започваше с малка буква
  70. }
  71. }
  72.  
  73. // Тук го направих по друг начин защото знам, че ще работи без да се бавя с отговора
  74. // и последния тест мина след като го оправих
  75. class Melolemonmelon extends Watermelon {
  76. constructor(weight,melonSort) {
  77. super(weight,melonSort);
  78. this.counter = 0;
  79. this.arr = ['Water', 'Fire', 'Earth', 'Air'];
  80. this.element = 'Water';
  81. }
  82.  
  83. morph() {
  84. this.arr.push(this.arr.shift());
  85. this.element = this.arr[0];
  86. return this;
  87. }
  88.  
  89. toString() {
  90. return `Element: ${this.element}\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex}`;
  91. }
  92.  
  93.  
  94. }
  95.  
  96. return { Melon, Watermelon, Firemelon, Earthmelon, Airmelon, Melolemonmelon };
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement