回答編集履歴

1

isCompleted関数に変更しました

2018/03/27 07:04

投稿

miyabi-sun
miyabi-sun

スコア21158

test CHANGED
@@ -50,11 +50,15 @@
50
50
 
51
51
  forは読みづらいので[for...of](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/for...of)で書き直すとこんな感じになります。
52
52
 
53
+ あと、`completedExerciseIdList.indexOf() !== -1`は読み物としては重いので、isCompletedという関数名で外出ししました。
54
+
53
55
 
54
56
 
55
57
  ```JavaScript
56
58
 
59
+ // isCompleted :: Exercise -> Boolean
60
+
57
- const inCompletedExerciseIdList = exercise =>
61
+ const isCompleted = exercise =>
58
62
 
59
63
  completedExerciseIdList.indexOf(
60
64
 
@@ -62,13 +66,15 @@
62
66
 
63
67
  ) !== -1 // -1か否かで確認した方がプログラマにとっては分かりやすい
64
68
 
69
+
70
+
65
71
  for (const section of this.props.chapter.sections) {
66
72
 
67
73
  for (const exercises of section.exercises) {
68
74
 
69
75
  this.setState({
70
76
 
71
- isCompleted: inCompletedExerciseIdList(exercises),
77
+ isCompleted: isCompleted(exercises),
72
78
 
73
79
  isOpen
74
80