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