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
let result = 0; | |
[1,2,3,4,5,6].forEach((n) => { | |
if (n % 2 === 0) { | |
result += n * n; | |
} | |
}); | |
console.log(result); |
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 result = [1,2,3,4,5,6] | |
.filter(n => n % 2 === 0) | |
.map(n => n * n) | |
.reduce((a, b) => a + b, 0); | |
console.log(result); // (2*2) + (4*4) + (6*6) |
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
// https://github.com/j5ik2o/ticket-price-modeling | |
// 解き方方針: 型で問題を解くよりも、料金表のように日本人の非エンジニアの人も読めて突っ込めるコード記述を目指す. | |
// 解き方方針: 配列でmap&sortの世界に引き込んで安い料金を選ぶようにする. | |
// 解いたのは "シネマシティズン" の場合だけ。 | |
// TODO 引数を型にして呼び出しに制約を設けるかはあとで考える。 | |
const movePayment = (ticketType, timeTypes) => { | |
var payments = | |
{"シネマシティズン": | |
{"平日〜20:00": 1000, |
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
interface Expression { | |
times(muptiplier: number): Expression; | |
plus(addend: Expression): Expression; | |
reduce(bank: Bank, to: string): Money | |
} | |
class Money implements Expression { | |
private _amount: number | |
private _currency: string |
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)}; | |
}); | |
reportData.total = total(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
const createReportData = require('./createReportData'); | |
function generateReadReport(readList, recommendList) { | |
const reportData = createReportData(readList, recommendList); | |
return renderPlainText(reportData); | |
} | |
function renderPlainText(reportData) { | |
let report = `name: ${reportData.userName}\n`; | |
report += '-----\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); | |
} | |
function createReportData(readList, recommendList) { | |
const reportData = {}; | |
reportData.userName = readList.name; | |
reportData.readBooks = readList.books | |
.map(book => { |
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, recommendList); | |
+ return renderPlainText(reportData); | |
} | |
function createReportData(readList, recommendList) { | |
@@ -42,7 +42,7 @@ function createReportData(readList, recommendList) { | |
} |
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); |
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 renderPlainText(reportData, recommendList) { | |
let report = `name: ${reportData.userName}\n`; | |
report += '-----\n'; | |
for (let book of reportData.readBooks) { | |
if (book.times >= 1) { | |
report += ` - ${book.name}: ${book.point} point\n`; | |
} | |
} | |
report += '-----\n'; | |
report += `total: ${total()} point`; |
NewerOlder