Skip to content

Commit 3f2e9bb

Browse files
authored
Translate "Comparing strings"
1 parent 2c48407 commit 3f2e9bb

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

1-js/05-data-types/03-string/article.md

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -454,38 +454,37 @@ Mari kita review cara-cara tersebut untuk menghindari kebingungan:
454454
| `substr(start, length)` | dari `start` ambil `length` karakter | `start` negatif diperbolehkan |
455455

456456
```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.
458457
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.
459458
460459
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`.
461460
```
462461

463-
## Comparing strings
462+
## Membandingkan string
464463

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.
466465

467-
Although, there are some oddities.
466+
Akan tetapi, ada beberapa pengecualian.
468467

469-
1. A lowercase letter is always greater than the uppercase:
468+
1. Huruf kecil selalu lebih besar dibanding huruf kapital:
470469

471470
```js run
472471
alert( 'a' > 'Z' ); // true
473472
```
474473

475-
2. Letters with diacritical marks are "out of order":
474+
2. Karakter dengan tanda diakritik "tidak sesuai urutan":
476475

477476
```js run
478477
alert( 'Österreich' > 'Zealand' ); // true
479478
```
480479

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.
482481

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.
484483

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.
486485

487486
`str.codePointAt(pos)`
488-
: Returns the code for the character at position `pos`:
487+
: Mengembalikan kode untuk karakter pada posisi `pos`:
489488

490489
```js run
491490
// 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
494493
```
495494

496495
`String.fromCodePoint(code)`
497-
: Creates a character by its numeric `code`
496+
: Membuat sebuah karakter berdasarkan `code` numeriknya
498497

499498
```js run
500499
alert( String.fromCodePoint(90) ); // Z
501500
```
502501

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:
504503
505504
```js run
506505
// 90 is 5a in hexadecimal system
507506
alert( '\u005a' ); // Z
508507
```
509508
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:
511510
512511
```js run
513512
let str = '';
@@ -520,38 +519,38 @@ alert( str );
520519
// ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜ
521520
```
522521
523-
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.
524523
525-
Now it becomes obvious why `a > Z`.
524+
Sekarang terlihat jelas kenapa `a > Z`.
526525
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).
528527
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`.
531530
532-
### Correct comparisons
531+
### Perbandingan yang benar
533532
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.
535534
536-
So, the browser needs to know the language to compare.
535+
Jadi, browser harus tahu bahasa yang digunakan untuk perbandingan.
537536
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).
539538
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.
541540
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:
543542
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`
545+
- Mengembalikan `0` apabila mereka sama.
547546
548-
For instance:
547+
Seperti contoh:
549548
550549
```js run
551550
alert( 'Österreich'.localeCompare('Zealand') ); // -1
552551
```
553552
554-
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.
555554
556555
## Internals, Unicode
557556

0 commit comments

Comments
 (0)