This file contains hidden or 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,14 +6,3 @@ function generateReadedReport(readedList, recommendList) { | |
| for (let readedBook of readedList.books) { | |
| - let currentPoint = 0; | |
| - if (readedBook.times === 0) { | |
| - currentPoint = 0; | |
| - } else if (!recommendList.map(recommend => recommend.asin).includes(readedBook.asin)) { | |
| - currentPoint = 1; | |
| - } else if (readedBook.times === 1) { | |
| - currentPoint = 3; | |
| - } else if (readedBook.times === 2) { |
This file contains hidden or 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
| { | |
| "testRegex": ".*-test\\.js$", | |
| "testEnvironment": "node" | |
| } |
This file contains hidden or 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 randomDiceTotal = () => { | |
| const first = Math.floor(Math.random() * 6) + 1 | |
| const second = Math.floor(Math.random() * 6) + 1 | |
| return first + second | |
| } | |
| const createJugeChoHan = (diceTotal = randomDiceTotal) => (players) => { | |
| const choHan = { 0: '丁', 1: '半' }[diceTotal() % 2] | |
| return players.map((player) => { |
This file contains hidden or 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 randomDiceTotal = () => { | |
| const first = Math.floor(Math.random() * 6) + 1 | |
| const second = Math.floor(Math.random() * 6) + 1 | |
| return first + second | |
| } | |
| const judgeChoHan = (players, diceTotal = randomDiceTotal) => { | |
| const choHan = { 0: '丁', 1: '半' }[diceTotal() % 2] | |
| return players.map((player) => { |
This file contains hidden or 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 randomDiceTotal = () => { | |
| const first = Math.floor(Math.random() * 6) + 1 | |
| const second = Math.floor(Math.random() * 6) + 1 | |
| return first + second | |
| } | |
| class ChoHan { | |
| // コンストラクタ インジェクションで差し替え可能 | |
| constructor(diceTotal = randomDiceTotal) { | |
| this.diceTotal = diceTotal |
This file contains hidden or 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
| class ChoHan { | |
| judge(players) { | |
| const choHan = { 0: '丁', 1: '半' }[this._total() % 2] | |
| return players.map((player) => { | |
| if (player.choHan === choHan) { | |
| return { ...player, result: 'win' } | |
| } else { | |
| return { ...player, result: 'lose' } | |
| } |
This file contains hidden or 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
| class ChoHan { | |
| // ランダムな振る舞いをするメソッドと | |
| judge(players) { | |
| const first = Math.floor(Math.random() * 6) + 1 | |
| const second = Math.floor(Math.random() * 6) + 1 | |
| return this._judge(players, first + second) | |
| } | |
| // ランダムな振る舞いしないメソッドに分離し、引数でコントロール | |
| _judge(players, total) { |
This file contains hidden or 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
| class ChoHan { | |
| judge(players) { | |
| // 2つのサイコロがランダムで、テストを難しくしている箇所。 どうやって分離する? | |
| const first = Math.floor(Math.random() * 6) + 1 | |
| const second = Math.floor(Math.random() * 6) + 1 | |
| const choHan = { 0: '丁', 1: '半' }[(first + second) % 2] | |
| return players.map((player) => { | |
| if (player.choHan === choHan) { | |
| return { ...player, result: 'win' } |
This file contains hidden or 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
| inc = (n) => n + 1 | |
| inc(2) | |
| square = (n) => n * n | |
| [1,2,3].map(inc) // [ 2, 3, 4 ] | |
| [1,2,3].map(square) // [ 1, 4, 9 ] | |
| compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x); | |
| incSquare = compose(inc, square) | |
| incSquare(3) // 10 |
This file contains hidden or 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
| import xs from 'xstream'; | |
| import delay from 'xstream/extra/delay'; | |
| const humanCProx = xs.create(); | |
| const humanA = humanCProx.map(increment).compose(delay(100)); | |
| const humanB = humanA.map(increment).compose(delay(100)); | |
| const humanC = humanB.map(increment).startWith(1).compose(delay(100)); | |
| humanCProx.imitate(humanC); | |
| function increment(n) { |