Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tickets(arr = [], criteria) {
- class Ticket {
- constructor(destination, price, status) {
- this.destination = destination;
- this.price = Number(price);
- this.status = status;
- }
- }
- const result = [];
- arr.forEach((line) => {
- const [destination, price, status] = line.split('|');
- const data = new Ticket(destination, price, status);
- result.push(data);
- });
- switch (criteria) {
- case 'destination':
- result.sort((a, b) => a.destination.localeCompare(b.destination));
- break;
- case 'price':
- result.sort((a, b) => a.price - b.price);
- break;
- case 'status':
- result.sort((a, b) => a.status.localeCompare(b.status));
- break;
- default:
- break;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement