Advertisement
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());
- const date = data.pop();
- let [day, month, year] = date.split(".").map(Number);
- let library = {};
- for (const line of data) {
- let book = new Book(...line.split(" "));
- library[book.title] = book.date.split(".").map(Number);
- }
- let result = Object.entries(library);
- result
- .filter(entry => {
- if (entry[1][2] === year) {
- if (entry[1][1] === month) {
- if (entry[1][0] > day) {
- return entry;
- }
- } else if (entry[1][1] > month) {
- return entry;
- }
- } else if (entry[1][2] > year) {
- return entry;
- }
- })
- .sort((a, b) => {
- if (b[1][2] === a[1][2]) {
- if (b[1][1] === a[1][1]) {
- if (a[1][0] === b[1][0]) {
- return a[0].localeCompare(b[0]);
- }
- return a[1][0] - b[1][0];
- }
- return a[1][1] - b[1][1];
- }
- return a[1][2] - b[1][2];
- })
- .forEach(entry => {
- let output = "";
- output += entry[0];
- output += " -> ";
- output += entry[1]
- .map(el => {
- if (el < 10) {
- return `0${el}`;
- } else {
- return `${el}`;
- }
- })
- .join(".");
- console.log(output);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement