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