Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tickets(input = [], criteria) {
  2.     let result = []
  3.     class Ticket {
  4.         constructor(destination, price, status) {
  5.             this.destination = destination;
  6.             this.price = Number(price);
  7.             this.status = status;
  8.         }
  9.     }
  10.  
  11.     for (const line of input) {
  12.         let [city, price, status] = line.split('|');
  13.         let data = new Ticket(city, price, status);
  14.         result.push(data)
  15.     }
  16.  
  17.  
  18.     if (criteria === 'destination') {
  19.  
  20.         let sorted = Array.from(result);
  21.         sorted.sort((a, b) => a[0].destination - b[0].destination)
  22.         console.log(sorted);
  23.  
  24.     } else if (criteria === 'price') {
  25.  
  26.     } else {
  27.  
  28.     }
  29. }
  30.  
  31. tickets(['Philadelphia|94.20|available',
  32.     'New York City|95.99|available',
  33.     'New York City|95.99|sold',
  34.     'Boston|126.20|departed'],
  35.     'destination')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement