Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test(input, sort) {
- class Ticket {
- constructor(destination, price, status) {
- this.destination = destination;
- this.price = Number(price);
- this.status = status;
- }
- }
- let arr = [];
- for (const row of input) {
- let [destination, price, availability] = row.split('|');
- arr.push(new Ticket(destination, price, availability));
- }
- switch (sort) {
- case "destination":
- arr.sort(function(a, b) {
- if (a.destination < b.destination) {
- return -1;
- }
- if (a.destination > b.destination) {
- return 1;
- }
- return 0;}
- );
- break;
- case "price":
- arr.sort();
- break;
- case "status":
- arr.sort(function(a, b) {
- if (a.status < b.status) {
- return -1;
- }
- if (a.status > b.status) {
- return 1;
- }
- return 0;}
- );
- break;
- default:
- break;
- }
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement