Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. //////////////////////////////////// 01. Data Class
  2. class Reguest {
  3. constructor(method, uri, version, message) {
  4. this.method = method;
  5. this.uri = uri;
  6. this.version = version;
  7. this.message = message;
  8. this.response = undefined;
  9. this.fulfilled = false;
  10. }
  11. }
  12. //////////////////////////////////// 02. Tickets
  13. function tickets(ticketsArr, sortingCriteria) {
  14. class Ticket{
  15. constructor(destination, price, status){
  16. this.destination = destination;
  17. this.price = price;
  18. this.status = status;
  19. }
  20. }
  21.  
  22. let unsortedTickets = [];
  23.  
  24. for(let ticket of ticketsArr){
  25. let[destination, price, status] = ticket.split('|');
  26. price = Number(price);
  27. unsortedTickets.push(new Ticket(destination, price, status));
  28. }
  29.  
  30. let sortedTckets;
  31. switch (sortingCriteria){
  32. case "destination":
  33. sortedTckets = unsortedTickets.sort((a, b) => a.destination.localeCompare(b.destination));
  34. break;
  35. case "price":
  36. sortedTckets = unsortedTickets.sort((a, b) => a.price - b.price);
  37. break;
  38. case "status":
  39. sortedTckets = unsortedTickets.sort((a, b) => a.status.localeCompare(b.status));
  40. break;
  41. }
  42.  
  43. return sortedTckets;
  44. }
  45. ////////////////////////////////////03. Unity <f*cking rats the remember every rat that they have f$cked>
  46. class Rat {
  47. constructor(name) {
  48. this.name = name;
  49. this.unitedRats = [];
  50. }
  51. unite(otherRat) {
  52. if (otherRat instanceof Rat) {
  53. this.unitedRats.push(otherRat);
  54. }
  55. }
  56. getRats() {
  57. return this.unitedRats
  58. }
  59. toString() {
  60. console.log(this.name);
  61. this.unitedRats.forEach(x => console.log("##" + x.name));
  62. }
  63. }
  64. //////////////////////////////////// 04. Length Limit
  65. class Stringer{
  66. constructor(string, length){
  67. this.innerString = string;
  68. this.innerLength = length;
  69. }
  70.  
  71. increase(length){
  72. this.innerLength += length;
  73. if(this.innerLength < 3){
  74. this.innerLength = 0;
  75. }
  76. }
  77.  
  78. decrease(length){
  79. this.innerLength -= length;
  80. if(this.innerLength < 3){
  81. this.innerLength = 0;
  82. }
  83. }
  84.  
  85. toString(){
  86. if(this.innerLength == 0){
  87. return "...";
  88. }
  89.  
  90. if(this.innerString.length > this.innerLength){
  91. this.innerString = this.innerString.substr(0, this.innerLength) + "...";
  92. }
  93. return this.innerString;
  94. }
  95. }
  96. ////////////////////////////////////06. Sorted List
  97.  
  98. class List {
  99. constructor() {
  100. this.list = [];
  101. this.size = this.list.length;
  102. }
  103. add(element) {
  104. this.list.push(element);
  105. this.size++;
  106. this.list.sort((a, b) => a - b);
  107. }
  108. remove(index) {
  109. if (index < this.list.length && index >= 0) {
  110. this.list.splice(index, 1);
  111. this.list.sort((a, b) => a - b);
  112. this.size--;
  113. return this.list;
  114.  
  115. }
  116. }
  117. get(index) {
  118. if (index < this.list.length && index >= 0) {
  119. return this.list[index];
  120. }
  121. }
  122.  
  123. }
  124. //////////////////////////////07. Instance Validation (i was too lazy while doing this XD so sorry for not writing readable things)
  125. class CheckingAccount {
  126. constructor(clientId, email, firstName, lastName) {
  127. if (clientId.length == 6) {
  128. this.clientId = clientId;
  129. } else {
  130. throw new TypeError("Client ID must be a 6-digit number");
  131. }
  132.  
  133. if (email.match(/[a-zA-Z]+@[a-zA-Z]+/gm)) {
  134. this.email = email;
  135. } else {
  136. throw new TypeError("Invalid e-mail");
  137. }
  138.  
  139. if (firstName.length >= 3 && firstName.length <= 20) {
  140. this.firstName = firstName;
  141. } else {
  142. throw new TypeError(`First name must be between 3 and 20 characters long`);
  143. }
  144. if (firstName.match(/^[a-zA-Z]+$/gm)) {
  145. this.firstName = firstName;
  146. } else {
  147. throw new TypeError(`First name must contain only Latin characters`);
  148. }
  149. if (lastName.length >= 3 && lastName.length <= 20) {
  150. this.lastName = lastName;
  151. } else {
  152. throw new TypeError(`Last name must be between 3 and 20 characters long`);
  153. }
  154. if (lastName.match(/^[a-zA-Z]+$/gm)) {
  155. this.lastName = lastName;
  156. } else {
  157. throw new TypeError(`Last name must contain only Latin characters`);
  158. }
  159.  
  160. }
  161. }
  162. ////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement