Advertisement
tochka

02. Tickets

Jul 2nd, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tickets(array, sortingCriteria) {
  2.  
  3.     class Tickets {
  4.         constructor(destination, price, status){
  5.             this.destination = destination;
  6.             this.price = price;
  7.             this.status = status;
  8.         }
  9.     }
  10.  
  11.     let tickets = [];
  12.  
  13.     for (let line of array) {
  14.         let [destinationName, price, status] = line.split('|').filter(a => a !== '');
  15.         price = parseFloat(price);
  16.         tickets.push(new Tickets(destinationName, price, status));
  17.     }
  18.  
  19.     if(sortingCriteria === 'destination'){
  20.         return ([...tickets].sort((a, b) => a.destination.localeCompare(b.destination)));
  21.     } else if (sortingCriteria === 'status'){
  22.         return ([...tickets].sort((a, b) => a.status.localeCompare(b.status)));
  23.     } else if(sortingCriteria === 'price'){
  24.         return ([...tickets].sort((a, b) => a.price - b.price));
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement