Skip to content

Commit 9437934

Browse files
committed
Merge branch '462-fix-array-exercise' of github.com:ut-code/utcode-learn into 462-fix-array-exercise
2 parents 352ddaa + 1bef64e commit 9437934

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

docs/1-trial-session/09-functions/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,16 @@ increment();
124124

125125
:::
126126

127-
## モジュール化
127+
## パーツに分割する
128128

129-
複雑な操作を <Term type="javascriptFunction">関数</Term> として <Term strong type="javascriptModularization">モジュール化</Term> して複数のブロックに分解することで、コードの可読性を上げることができます。
129+
複雑な操作を複数の <Term type="javascriptFunction">関数</Term> ブロックに分解することで、コードの可読性を上げることができます。この操作を <Term strong type="javascriptModularization">モジュール化</Term> と呼びます。
130+
パーツに分割すると、次のようなメリットがあります。
130131

131-
モジュール化前:
132+
- ブロックあたりのコードが短くなるので、読みやすい
133+
- パーツごとにテストができるので、デバッグがしやすい
134+
- 汎用性のあるパーツなら、使いまわしができる
135+
136+
以下の例では、階段を表示する操作の中の、文字列を繰り返す操作を `repeat` 関数というパーツに分けています。
132137

133138
```javascript
134139
const stringToRepeat = "";
@@ -142,26 +147,21 @@ for (let i = 0; i < 10; i += 1) {
142147
}
143148
```
144149

145-
モジュール化後:
146-
147150
```javascript
148-
function repeat(stringToRepeat, times) {
151+
function repeat(stringToRepeat, count) {
149152
let result = "";
150-
for (let j = 0; j < times; j += 1) {
153+
for (let j = 0; j < count; j += 1) {
151154
result += stringToRepeat;
152155
}
153156
return result;
154157
}
158+
155159
for (let i = 0; i < 10; i += 1) {
156160
document.write(repeat("", i));
157161
document.write("<br>");
158162
}
159163
```
160164

161-
:::note
162-
この例における`repeat`<Term type="javascriptFunction">関数</Term>は、第一<Term type="javascriptParameter">引数</Term>の<Term type="javascriptString">文字列</Term>を第二<Term type="javascriptParameter">引数</Term>回だけ繰り返し<Term type="javascriptStringConcatenation">足した</Term>ものを返します。
163-
:::
164-
165165
---
166166

167167
## 基礎課題

docs/1-trial-session/10-array/_samples/array-sum-simple-for/script.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const numbers = [-3, -1, 9, -10, 3, 7, 6, 1, 0, 5];
1+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
22

33
let sum = 0;
44
for (let i = 0; i < numbers.length; i += 1) {

docs/1-trial-session/10-array/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Answer from "@site/src/components/Answer";
99

1010
## 配列
1111

12-
JavaScript における配列は、複数の値を並べて一つにまとめたオブジェクトです`[` から `]` で囲まれた部分は配列を生成する式になります。
12+
JavaScript における配列は、複数の値を並べて一つにまとめた値です`[` から `]` で囲まれた部分は配列を生成する式になります。
1313

1414
```javascript
1515
const studentNames = ["田中", "佐藤", "鈴木"];
@@ -149,7 +149,7 @@ document.write(`配列の合計値は: ${sum} です。`);
149149
`for 〜 of` 文を使わず、次のように書くこともできます。
150150

151151
```javascript
152-
const numbers = [-3, -1, 9, -10, 3, 7, 6, 1, 0, 5];
152+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
153153

154154
let sum = 0;
155155
for (let i = 0; i < numbers.length; i += 1) {

0 commit comments

Comments
 (0)