Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////// 01. Data Class
- class Reguest {
- constructor(method, uri, version, message) {
- this.method = method;
- this.uri = uri;
- this.version = version;
- this.message = message;
- this.response = undefined;
- this.fulfilled = false;
- }
- }
- //////////////////////////////////// 02. Tickets
- function tickets(ticketsArr, sortingCriteria) {
- class Ticket{
- constructor(destination, price, status){
- this.destination = destination;
- this.price = price;
- this.status = status;
- }
- }
- let unsortedTickets = [];
- for(let ticket of ticketsArr){
- let[destination, price, status] = ticket.split('|');
- price = Number(price);
- unsortedTickets.push(new Ticket(destination, price, status));
- }
- let sortedTckets;
- switch (sortingCriteria){
- case "destination":
- sortedTckets = unsortedTickets.sort((a, b) => a.destination.localeCompare(b.destination));
- break;
- case "price":
- sortedTckets = unsortedTickets.sort((a, b) => a.price - b.price);
- break;
- case "status":
- sortedTckets = unsortedTickets.sort((a, b) => a.status.localeCompare(b.status));
- break;
- }
- return sortedTckets;
- }
- ////////////////////////////////////03. Unity <f*cking rats the remember every rat that they have f$cked>
- class Rat {
- constructor(name) {
- this.name = name;
- this.unitedRats = [];
- }
- unite(otherRat) {
- if (otherRat instanceof Rat) {
- this.unitedRats.push(otherRat);
- }
- }
- getRats() {
- return this.unitedRats
- }
- toString() {
- console.log(this.name);
- this.unitedRats.forEach(x => console.log("##" + x.name));
- }
- }
- //////////////////////////////////// 04. Length Limit
- class Stringer{
- constructor(string, length){
- this.innerString = string;
- this.innerLength = length;
- }
- increase(length){
- this.innerLength += length;
- if(this.innerLength < 3){
- this.innerLength = 0;
- }
- }
- decrease(length){
- this.innerLength -= length;
- if(this.innerLength < 3){
- this.innerLength = 0;
- }
- }
- toString(){
- if(this.innerLength == 0){
- return "...";
- }
- if(this.innerString.length > this.innerLength){
- this.innerString = this.innerString.substr(0, this.innerLength) + "...";
- }
- return this.innerString;
- }
- }
- ////////////////////////////////////06. Sorted List
- class List {
- constructor() {
- this.list = [];
- this.size = this.list.length;
- }
- add(element) {
- this.list.push(element);
- this.size++;
- this.list.sort((a, b) => a - b);
- }
- remove(index) {
- if (index < this.list.length && index >= 0) {
- this.list.splice(index, 1);
- this.list.sort((a, b) => a - b);
- this.size--;
- return this.list;
- }
- }
- get(index) {
- if (index < this.list.length && index >= 0) {
- return this.list[index];
- }
- }
- }
- //////////////////////////////07. Instance Validation (i was too lazy while doing this XD so sorry for not writing readable things)
- class CheckingAccount {
- constructor(clientId, email, firstName, lastName) {
- if (clientId.length == 6) {
- this.clientId = clientId;
- } else {
- throw new TypeError("Client ID must be a 6-digit number");
- }
- if (email.match(/[a-zA-Z]+@[a-zA-Z]+/gm)) {
- this.email = email;
- } else {
- throw new TypeError("Invalid e-mail");
- }
- if (firstName.length >= 3 && firstName.length <= 20) {
- this.firstName = firstName;
- } else {
- throw new TypeError(`First name must be between 3 and 20 characters long`);
- }
- if (firstName.match(/^[a-zA-Z]+$/gm)) {
- this.firstName = firstName;
- } else {
- throw new TypeError(`First name must contain only Latin characters`);
- }
- if (lastName.length >= 3 && lastName.length <= 20) {
- this.lastName = lastName;
- } else {
- throw new TypeError(`Last name must be between 3 and 20 characters long`);
- }
- if (lastName.match(/^[a-zA-Z]+$/gm)) {
- this.lastName = lastName;
- } else {
- throw new TypeError(`Last name must contain only Latin characters`);
- }
- }
- }
- ////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement