simeonshopov

Tickets

Jun 10th, 2021
663
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(info, sortingParam) {
  2.   class Ticket {
  3.     constructor(tokens) {
  4.       this.destination = tokens[0];
  5.       this.price = Number(tokens[1]);
  6.       this.status = tokens[2];
  7.     }
  8.   }
  9.  
  10.   const tickets = [];
  11.   for (const stuff of info) { tickets.push(new Ticket(stuff.split('|'))); }
  12.  
  13.   return tickets.sort(function (a, b) { if (sortingParam != 'price') { return a[sortingParam].localeCompare(b[sortingParam]); } else { return a.price - b.price; } });
  14. }
RAW Paste Data