Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(inputArray, sortCriteria) {
  2.     class Ticket {
  3.         constructor(destination, price, status) {
  4.             this.destination = destination;
  5.             this.price = Number(price);
  6.             this.status = status;
  7.         }
  8.     }
  9.     let sort = {
  10.         "destination": (a,b)=>a[sortCriteria].localeCompare(b[sortCriteria]),
  11.         "status": (a,b)=>a[sortCriteria].localeCompare(b[sortCriteria]),
  12.         "price": (a,b)=>a[sortCriteria]- (b[sortCriteria]),
  13.     };
  14.     return storeTicket = inputArray.reduce((a,b) => {
  15.         [destination, price, status] = b.split("|");
  16.         a.push(new Ticket(destination, price, status));
  17.         return a;
  18.     },[]).sort(sort[sortCriteria]);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement