Advertisement
Lulunga

Classes 02. Tickets

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