You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/03-string/article.md
+28-29Lines changed: 28 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -454,38 +454,37 @@ Mari kita review cara-cara tersebut untuk menghindari kebingungan:
454
454
|`substr(start, length)`| dari `start` ambil `length` karakter |`start` negatif diperbolehkan |
455
455
456
456
```smart header="Cara mana yang harus kita gunakan?"
457
-
All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core JavaScript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere.
458
457
Semuanya dapat melakukan pekerjaannya. Secara formal, `substr` memiliki kekurangan: fungsi ini tidak tercantum di spesifikasi inti Javascript, tetapi di Annex B, yang mencakup hanya fitur browser yang ada karena alasan historis. Jadi, environment non-browser mungkin gagal untuk mendukungnya. Tetapi dalam praktik fungsi ini bekerja di mana saja.
459
458
460
459
Dibandingkan dengan dua varian yang lain, `slice` lebih fleksibel, karena memperbolehkan parameter negatif dan lebih pendek untuk ditulis. Jadi, dari ketiga cara sudah cukup untuk mengingat `slice`.
461
460
```
462
461
463
-
## Comparing strings
462
+
## Membandingkan string
464
463
465
-
As we know from the chapter<info:comparison>, strings are compared character-by-character in alphabetical order.
464
+
Seperti yang kita tahu dari bab<info:comparison>, string dibandingkan karakter per karakter dengan urutan alfabet.
466
465
467
-
Although, there are some oddities.
466
+
Akan tetapi, ada beberapa pengecualian.
468
467
469
-
1.A lowercase letter is always greater than the uppercase:
468
+
1.Huruf kecil selalu lebih besar dibanding huruf kapital:
470
469
471
470
```js run
472
471
alert( 'a'>'Z' ); // true
473
472
```
474
473
475
-
2.Letters with diacritical marks are "out of order":
474
+
2.Karakter dengan tanda diakritik "tidak sesuai urutan":
476
475
477
476
```js run
478
477
alert( 'Österreich' > 'Zealand' ); // true
479
478
```
480
479
481
-
This may lead to strange results if we sort these country names. Usually people would expect `Zealand`to come after `Österreich`in the list.
480
+
Hal ini dapat menyebabkan hasil yang aneh apabila kita mengurutkan nama-nama negara. Biasanya orang mengharapkan `Zealand`muncul setelah `Österreich`di daftar.
482
481
483
-
To understand what happens, let's review the internal representation of strings in JavaScript.
482
+
Untuk memahami apa yang terjadi, mari kita review representasi internal string di Javascript.
484
483
485
-
All strings are encoded using [UTF-16](https://en.wikipedia.org/wiki/UTF-16). That is: each character has a corresponding numeric code. There are special methods that allow to get the character for the code and back.
484
+
Semua string menggunakan encoding [UTF-16](https://en.wikipedia.org/wiki/UTF-16). Yaitu: setiap karakter memiliki masing-masing kode numerik. Ada method spesial yang memperbolehkan kita untuk mengambil karakter dari kode dan sebaliknya.
486
485
487
486
`str.codePointAt(pos)`
488
-
: Returns the code for the character at position `pos`:
487
+
:Mengembalikan kode untuk karakter pada posisi`pos`:
489
488
490
489
```js run
491
490
// different case letters have different codes
@@ -494,20 +493,20 @@ All strings are encoded using [UTF-16](https://en.wikipedia.org/wiki/UTF-16). Th
494
493
```
495
494
496
495
`String.fromCodePoint(code)`
497
-
: Creates a character by its numeric `code`
496
+
:Membuat sebuah karakter berdasarkan `code` numeriknya
498
497
499
498
```js run
500
499
alert( String.fromCodePoint(90) ); // Z
501
500
```
502
501
503
-
We can also add unicode characters by their codes using `\u` followed by the hex code:
502
+
Kita juga dapat membuat karakter unicode dengan kode mereka menggunakan `\u` yang diikuti oleh kode heksadesimal:
504
503
505
504
```js run
506
505
// 90 is 5a in hexadecimal system
507
506
alert( '\u005a' ); // Z
508
507
```
509
508
510
-
Now let's see the characters with codes `65..220` (the latin alphabet and a little bit extra) by making a string of them:
509
+
Sekarang mari kita lihat karakter dengan kode di antara `65..220` (alfabet latin dan sedikit tambahan) dengan membuat string yang terdiri dari mereka:
See? Capital characters go first, then a few special ones, then lowercase characters, and`Ö`near the end of the output.
522
+
Kan? Huruf kapital muncul pertama, lalu beberapa karakter spesial, lalu huruf kecil, dan`Ö`berada di dekat akhir string.
524
523
525
-
Now it becomes obvious why`a > Z`.
524
+
Sekarang terlihat jelas kenapa`a >Z`.
526
525
527
-
The characters are compared by their numeric code. The greater code means that the character is greater. The code for `a` (97) is greater than the code for`Z` (90).
526
+
Karakter-karakter dibandingkan berdasarkan kode numeriknya. Kode yang lebih besar berarti karakter tersebut lebih besar. Kode untuk `a` (97) lebih besar dibandingkan dengan kode untuk`Z` (90).
528
527
529
-
-All lowercase letters go after uppercase letters because their codes are greater.
530
-
-Some letters like`Ö`stand apart from the main alphabet. Here, it's code is greater than anything from`a` to `z`.
528
+
- Semua huruf kecil muncul setelah huruf kapital karena kode mereka lebih besar.
529
+
- Beberapa karakter seperti`Ö`terpisah dari alfabet utama. Disini, kodenya lebih besar dibandingkan semua karakter dari`a` to `z`.
531
530
532
-
### Correct comparisons
531
+
### Perbandingan yang benar
533
532
534
-
The "right" algorithm to do string comparisons is more complex than it may seem, because alphabets are different for different languages.
533
+
Algoritma yang "benar" untuk melakukan perbandingan string lebih kompleks dari kelihatannya, setiap bahasa memiliki alfabet mereka masing-masing.
535
534
536
-
So, the browser needs to know the language to compare.
535
+
Jadi, browser harus tahu bahasa yang digunakan untuk perbandingan.
537
536
538
-
Luckily, all modern browsers (IE10- requires the additional library [Intl.JS](https://github.com/andyearnshaw/Intl.js/)) support the internationalization standard[ECMA 402](http://www.ecma-international.org/ecma-402/1.0/ECMA-402.pdf).
537
+
Beruntungnya, semua browser modern (IE10- memerlukan library tambahan [Intl.JS](https://github.com/andyearnshaw/Intl.js/)) mendukung standart internasionalisasi [ECMA 402](http://www.ecma-international.org/ecma-402/1.0/ECMA-402.pdf).
539
538
540
-
It provides a special method to compare strings in different languages, following their rules.
539
+
Hal tersebut menyediakan cara spesial untuk membandingkan stringi di berbeda bahasa, mengikuti peraturan mereka.
541
540
542
-
The call [str.localeCompare(str2)](mdn:js/String/localeCompare)returns an integer indicating whether `str`is less, equal or greater than `str2`according to the language rules:
541
+
Method [str.localeCompare(str2)](mdn:js/String/localeCompare) mengembalikan sebuah interger yang menandakan apakah `str`lebih kecil, sama dengan atau lebih besar dari `str2`menurut peraturan-peraturan bahasa:
543
542
544
-
-Returns a negative number if `str`is less than`str2`.
545
-
-Returns a positive number if `str`is greater than`str2`.
546
-
-Returns`0`if they are equivalent.
543
+
- Mengembalikan nilai negatif jika `str`lebih kecil dibandingkan`str2`
544
+
- Mengembalikan nilai positif jika `str`lebih besar dibandingkan`str2`
This method actually has two additional arguments specified in [the documentation](mdn:js/String/localeCompare), which allows it to specify the language (by default taken from the environment, letter order depends on the language) and setup additional rules like case sensitivity or should`"a"` and `"á"`be treated as the same etc.
553
+
Method ini sebenarnya menerima 2 argumen tambahan yang disebutkan di [dokumentasi](mdn:js/String/localeCompare), yang memperbolehkan untuk menyebutkan bahasa (yang biasanya diambil dari environment, urutan huruf bergantung dari bahasa) dan menyebutkan peraturan-peraturan tambahan seperti case sensitivity atau apakah`"a"` and `"á"`dianggap sama dan seterusnya.
0 commit comments