Skip to content

Instantly share code, notes, and snippets.

@@ -1,6 +1,6 @@
function generateReadReport(readList, recommendList) {
const reportData = createReportData(readList, recommendList);
- return renderPlainText(reportData, recommendList);
+ return renderPlainText(reportData);
}
function createReportData(readList, recommendList) {
@@ -42,7 +42,7 @@ function createReportData(readList, recommendList) {
}
@@ -10,8 +10,14 @@ function createReportData(readList, recommendList) {
.map(book => {
return {...book, point: point(book)};
});
+ reportData.total = total(reportData);
return reportData;
+ function total(reportData) {
+ return reportData.readBooks
+ .reduce((total, book) => total + book.point, 0);
@haru01
haru01 / 15.js
Last active April 4, 2019 01:41
function renderPlainText(reportData, recommendList) {
let report = `name: ${reportData.userName}\n`;
report += '-----\n';
for (let book of reportData.readBooks) {
if (book.times >= 1) {
report += ` - ${book.name}: ${book.point} point\n`;
}
}
report += '-----\n';
report += `total: ${total()} point`;
@haru01
haru01 / 14.js
Last active April 4, 2019 01:41
function createReportData(readList, recommendList) {
const reportData = {};
reportData.userName = readList.name;
reportData.readBooks = readList.books
.map(book => {
return {...book, point: point(book)};
});
return reportData;
function point(readBook) {
@@ -5,11 +5,12 @@ function generateReadReport(readList, recommendList) {
function createReportData(readList, recommendList) {
const reportData = {};
+ reportData.userName = readList.name;
return reportData;
}
function renderPlainText(reportData, readList, recommendList) {
- let report = `name: ${readList.name}\n`;
@@ -6,13 +6,14 @@ function generateReadReport(readList, recommendList) {
function createReportData(readList, recommendList) {
const reportData = {};
reportData.userName = readList.name;
+ reportData.readBooks = readList.books;
return reportData;
}
function renderPlainText(reportData, readList, recommendList) {
let report = `name: ${reportData.userName}\n`;
@@ -1,6 +1,6 @@
function generateReadReport(readList, recommendList) {
const reportData = createReportData(readList, recommendList);
- return renderPlainText(reportData, readList, recommendList);
+ return renderPlainText(reportData, recommendList);
}
function createReportData(readList, recommendList) {
@@ -10,7 +10,7 @@ function createReportData(readList, recommendList) {
return reportData;
@haru01
haru01 / 10.js
Last active April 4, 2019 01:28
function generateReadReport(readList, recommendList) {
const reportData = createReportData(readList, recommendList);
return renderPlainText(reportData, readList, recommendList);
}
function createReportData(readList, recommendList) {
const reportData = {};
return reportData;
}
function generateReadReport(readList, recommendList) {
let report = `name: ${readList.name}\n`;
report += '-----\n';
for (let book of readList.books) {
if (book.times >= 1) {
report += ` - ${book.name}: ${point(book)} point\n`;
}
}
report += '-----\n';
report += `total: ${total()} point`;
@@ -6,14 +6,3 @@ function generateReadedReport(readedList, recommendList) {
for (let readedBook of readedList.books) {
- let currentPoint = 0;
- if (readedBook.times === 0) {
- currentPoint = 0;
- } else if (!recommendList.map(recommend => recommend.asin).includes(readedBook.asin)) {
- currentPoint = 1;
- } else if (readedBook.times === 1) {
- currentPoint = 3;
- } else if (readedBook.times === 2) {