Skip to content

Commit f202add

Browse files
authored
Merge pull request #68 from zdzc/master
translate closure
2 parents 34b86dc + a580b0d commit f202add

File tree

13 files changed

+286
-285
lines changed

13 files changed

+286
-285
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
The answer: **0,1.**
1+
Jawaban: **0,1.**
22

3-
Functions `counter` and `counter2` are created by different invocations of `makeCounter`.
3+
Fungsi `counter` dan `counter2` dibuat dengan panggilan fungsi `makeCounter` yang berbeda.
44

5-
So they have independent outer Lexical Environments, each one has its own `count`.
5+
Jadi mereka memiliki lingkungan leksikal yang berbeda, dengan `count` mereka masing-masing.

1-js/06-advanced-functions/03-closure/1-counter-independent/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
importance: 5
1+
nilai penting: 5
22

33
---
44

5-
# Are counters independent?
5+
# Apakah para counter independen?
66

7-
Here we make two counters: `counter` and `counter2` using the same `makeCounter` function.
7+
Di sini kita membuat dua counter: `counter` dan `counter2` menggunakan fungsi `makeCounter` yang sama.
88

9-
Are they independent? What is the second counter going to show? `0,1` or `2,3` or something else?
9+
Apakah mereka independen? Apa yang akan counter kedua munculkan? `0,1` atau `2,3` atau yang lainnya?
1010

1111
```js
1212
function makeCounter() {

1-js/06-advanced-functions/03-closure/2-counter-object-independent/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
Surely it will work just fine.
2+
Tentu saja hal tersebut akan bekerja.
33

4-
Both nested functions are created within the same outer Lexical Environment, so they share access to the same `count` variable:
4+
Kedua fungsi bersarang dibuat dengan lingkungan leksikal yang sama, jadi mereka membagi akses ke variabel `count` yang sama:
55

66
```js run
77
function Counter() {

1-js/06-advanced-functions/03-closure/2-counter-object-independent/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
importance: 5
1+
nilai penting: 5
22

33
---
44

5-
# Counter object
5+
# Objek counter
66

7-
Here a counter object is made with the help of the constructor function.
7+
Disini kita memiliki objek counter yang dibuat dengan bantuan fungsi konstruktor.
88

9-
Will it work? What will it show?
9+
Apakah hal tersebut akan bekerja? Apa yang akan muncul?
1010

1111
```js
1212
function Counter() {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
The result is **an error**.
1+
Hasilnya yaitu **sebuah error**.
22

3-
The function `sayHi` is declared inside the `if`, so it only lives inside it. There is no `sayHi` outside.
3+
Fungsi `sayHi` dideklarasikan di dalam `if`, jadi fungsi tersebut hanya hidup di dalamnya. Tidak ada fungsi `sayHi` di luar.

1-js/06-advanced-functions/03-closure/3-function-in-if/task.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
# Function in if
2+
# Fungsi di dalam if
33

4-
Look at the code. What will be the result of the call at the last line?
4+
Lihatlah kode di bawah ini. Apa hasil dari panggilan fungsi di baris terakhir?
55

66
```js run
77
let phrase = "Hello";

1-js/06-advanced-functions/03-closure/4-closure-sum/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
For the second parentheses to work, the first ones must return a function.
1+
Agar kurung kedua berhasil, yang pertama harus mengembalikan sebuah fungsi.
22

3-
Like this:
3+
Seperti ini:
44

55
```js run
66
function sum(a) {
77

88
return function(b) {
9-
return a + b; // takes "a" from the outer lexical environment
9+
return a + b; // mengambil "a" dari lingkungan leksikal luar
1010
};
1111

1212
}

1-js/06-advanced-functions/03-closure/4-closure-sum/task.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
importance: 4
1+
nilai penting: 4
22

33
---
44

5-
# Sum with closures
5+
# Penjumlahan dengan closure
66

7-
Write function `sum` that works like this: `sum(a)(b) = a+b`.
7+
Buatlah sebuah fungsi `sum` yang bekerja seperti ini: `sum(a)(b) = a+b`.
88

9-
Yes, exactly this way, using double parentheses (not a mistype).
9+
Ya, seperti ini, dengan kurung ganda (bukan salah ketik).
1010

11-
For instance:
11+
Sebagai contoh:
1212

1313
```js
1414
sum(1)(2) = 3

1-js/06-advanced-functions/03-closure/6-filter-through-function/task.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
importance: 5
1+
nilai penting: 5
22

33
---
44

5-
# Filter through function
5+
# Filter dengan fungsi
66

7-
We have a built-in method `arr.filter(f)` for arrays. It filters all elements through the function `f`. If it returns `true`, then that element is returned in the resulting array.
7+
Kita memiliki method bawaan `arr.filter(f)` untuk array. Method tersebut menyaring seluruh elemen menggunakan fungsi `f`. Apabila mengembalikan `true`, maka elemen tersebut dikembalikan di array hasil.
88

9-
Make a set of "ready to use" filters:
9+
Buatlah filter "yang siap pakai":
1010

11-
- `inBetween(a, b)` -- between `a` and `b` or equal to them (inclusively).
12-
- `inArray([...])` -- in the given array.
11+
- `inBetween(a, b)` -- antara `a` dan `b` atau sama dengan (inklusif).
12+
- `inArray([...])` -- terkandung di dalam array.
1313

14-
The usage must be like this:
14+
Penggunaannya harus seperti ini:
1515

16-
- `arr.filter(inBetween(3,6))` -- selects only values between 3 and 6.
17-
- `arr.filter(inArray([1,2,3]))` -- selects only elements matching with one of the members of `[1,2,3]`.
16+
- `arr.filter(inBetween(3,6))` -- menyimpan hanya nilai di antara 3 dan 6.
17+
- `arr.filter(inArray([1,2,3]))` -- menyimpan elemen apabila sama dengan salah satu dari `[1,2,3]`.
1818

19-
For instance:
19+
Sebagai contoh:
2020

2121
```js
22-
/* .. your code for inBetween and inArray */
22+
/* .. implementasi inBetween dan inArray */
2323
let arr = [1, 2, 3, 4, 5, 6, 7];
2424

2525
alert( arr.filter(inBetween(3, 6)) ); // 3,4,5,6
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
importance: 5
1+
nilai penting: 5
22

33
---
44

5-
# Sort by field
5+
# Urutkan berdasarkan field
66

7-
We've got an array of objects to sort:
7+
Kita memiliki array objek untuk diurutkan:
88

99
```js
1010
let users = [
@@ -14,23 +14,23 @@ let users = [
1414
];
1515
```
1616

17-
The usual way to do that would be:
17+
Cara yang biasa dilakukan yaitu:
1818

1919
```js
20-
// by name (Ann, John, Pete)
20+
// berdasarkan name (Ann, John, Pete)
2121
users.sort((a, b) => a.name > b.name ? 1 : -1);
2222

23-
// by age (Pete, Ann, John)
23+
// berdasarkan age (Pete, Ann, John)
2424
users.sort((a, b) => a.age > b.age ? 1 : -1);
2525
```
2626

27-
Can we make it even less verbose, like this?
27+
Apakah kita dapat membuatnya lebih ringkas, seperti ini?
2828

2929
```js
3030
users.sort(byField('name'));
3131
users.sort(byField('age'));
3232
```
3333

34-
So, instead of writing a function, just put `byField(fieldName)`.
34+
Jadi, daripada menulis sebuah fungsi, cukup tulis `byField(fieldName)`.
3535

36-
Write the function `byField` that can be used for that.
36+
Tulislah fungsi `byField` yang dapat digunakan untuk itu.

0 commit comments

Comments
 (0)