Last active
April 4, 2019 01:47
-
-
Save haru01/eb6be92e4efb388020a8fea63180f044 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
@@ -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); | |
+ } | |
+ | |
function point(readBook) { | |
if (readBook.times <= 0) { | |
return 0; | |
@@ -45,13 +51,8 @@ function renderPlainText(reportData, recommendList) { | |
} | |
} | |
report += '-----\n'; | |
- report += `total: ${total()} point`; | |
+ report += `total: ${reportData.total} point`; | |
return report; | |
- | |
- function total() { | |
- return reportData.readBooks | |
- .reduce((total, book) => total + book.point, 0); | |
- } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment