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 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`; |
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 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) { |
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
@@ -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; |
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
@@ -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`; |
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
@@ -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`; |
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 generateReadReport(readList, recommendList) { | |
const reportData = createReportData(readList, recommendList); | |
return renderPlainText(reportData, readList, recommendList); | |
} | |
function createReportData(readList, recommendList) { | |
const reportData = {}; | |
return reportData; | |
} |
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 generateReadReport(readList, recommendList) { | |
return renderPlainText(readList, recommendList); | |
} | |
function renderPlainText(readList, recommendList) { | |
let report = `name: ${readList.name}\n`; | |
report += '-----\n'; | |
for (let readBook of readList.books) { | |
if (readBook.times >= 1) { | |
report += ` - ${readBook.name}: ${point(readBook)} point\n`; |
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
@@ -12,9 +12,6 @@ function generateReadedReport(readedList, recommendList) { | |
function total() { | |
- let totalPoint = 0; | |
- for (let readedBook of readedList.books) { | |
- totalPoint += point(readedBook); | |
- } | |
- return totalPoint; | |
+ return readedList.books | |
+ .reduce((total, book) => total + point(book), 0); |
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
const generateReadedReport = require('./generateReadedReport'); | |
test('読書レポーター', () => { | |
const recommendList = [ | |
{asin: '0321146530' }, // Test Driven Development | |
{asin: '0596802293' }, // The Art of Readable Code | |
{asin: 'B005OYHF0A' }, // Working Effectively with Legacy Code | |
{asin: 'B075LRM681' }, // Clean Architecture | |
{asin: 'B07B9F83WM' }, // Accelerate | |
{asin: 'B07LCM8RG2' }, // Refactoring |
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`; |