回答編集履歴
1
isCompleted関数に変更しました
answer
CHANGED
@@ -24,16 +24,19 @@
|
|
24
24
|
その結果を元に`this.setState({ isCompleted, isOpen })`を実行しています。
|
25
25
|
|
26
26
|
forは読みづらいので[for...of](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/for...of)で書き直すとこんな感じになります。
|
27
|
+
あと、`completedExerciseIdList.indexOf() !== -1`は読み物としては重いので、isCompletedという関数名で外出ししました。
|
27
28
|
|
28
29
|
```JavaScript
|
30
|
+
// isCompleted :: Exercise -> Boolean
|
29
|
-
const
|
31
|
+
const isCompleted = exercise =>
|
30
32
|
completedExerciseIdList.indexOf(
|
31
33
|
this.props.courseId + "/" + exercise.exerciseId
|
32
34
|
) !== -1 // -1か否かで確認した方がプログラマにとっては分かりやすい
|
35
|
+
|
33
36
|
for (const section of this.props.chapter.sections) {
|
34
37
|
for (const exercises of section.exercises) {
|
35
38
|
this.setState({
|
36
|
-
isCompleted:
|
39
|
+
isCompleted: isCompleted(exercises),
|
37
40
|
isOpen
|
38
41
|
});
|
39
42
|
}
|