Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- class Book {
- constructor(title, author, publisher, releaseDate, isbn, price) {
- this.title = title;
- this.author = author;
- this.publisher = publisher;
- this.date = releaseDate;
- this.isbn = isbn;
- this.price = price;
- }
- }
- let data = input.slice(0).filter(x => x !== "");
- const count = Number(data.shift());
- let library = {};
- for (const line of data) {
- let book = new Book(...line.split(" "));
- if (!library[book.author]) {
- library[book.author] = 0;
- }
- library[book.author] += Number(book.price);
- }
- Object.entries(library)
- .sort((a, b) => {
- if (a[1] == b[1]) {
- return a[0].localeCompare(b[0]);
- }
- return b[1] - a[1];
- })
- .forEach(pair => {
- console.log(`${pair[0]} -> ${pair[1].toFixed(2)}`);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment