Skip to content

Instantly share code, notes, and snippets.

@haru01
Last active April 4, 2019 01:13
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/9bec3ea631861bf3a8c0734d75ba7ebb to your computer and use it in GitHub Desktop.
Save haru01/9bec3ea631861bf3a8c0734d75ba7ebb to your computer and use it in GitHub Desktop.
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`;
return report;
function total() {
return readList.books
.reduce((total, book) => total + point(book), 0);
}
function point(readBook) {
if (readBook.times <= 0) {
return 0;
}
if (notRecommendBook()) {
return 1;
}
if (readBook.times >= 3) {
return 8;
} else if (readBook.times === 2) {
return 5;
} else if (readBook.times === 1) {
return 3;
} else {
return 0;
}
function notRecommendBook() {
return !recommendList.map(recommend => recommend.asin).includes(readBook.asin);
}
}
}
module.exports = generateReadReport;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment