Skip to content

Instantly share code, notes, and snippets.

@haru01
Last active March 3, 2019 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haru01/b707f10f37e8fc54e8ec6cab93ada36a to your computer and use it in GitHub Desktop.
Save haru01/b707f10f37e8fc54e8ec6cab93ada36a to your computer and use it in GitHub Desktop.
function generateReadedReport(readedList, recommendList) {
let report = `name: ${readedList.name}\n`;
report += '-----\n';
for (let readedBook of readedList.books) {
if (readedBook.times >= 1) {
report += ` - ${readedBook.name}: ${point(readedBook)} point\n`;
}
}
report += '-----\n';
report += `total: ${total()} point`;
return report;
function total() {
return readedList.books
.reduce((total, book) => total + point(book), 0);
}
function point(readedBook) {
if (readedBook.times <= 0) {
return 0;
}
if (notRecommendBook()) {
return 1;
}
if (readedBook.times >= 3) {
return 8;
} else if (readedBook.times === 2) {
return 5;
} else if (readedBook.times === 1) {
return 3;
} else {
return 0;
}
function notRecommendBook() {
return !recommendList.map(recommend => recommend.asin).includes(readedBook.asin);
}
}
}
module.exports = generateReadedReport;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment