Last active
March 3, 2019 22:08
-
-
Save haru01/b707f10f37e8fc54e8ec6cab93ada36a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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