SHARE
TWEET

Untitled

a guest Oct 15th, 2019 65 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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top