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
Algoritmas eilučių palyginimui yra labai paprastas:
47
47
48
48
1. Palyginti abiejų eilučių pirmus ženklus.
49
-
2. Jeigu pirmas ženklas iš pirmos eilutės yra didesnis (ar mažesnis) negu kitos eilutės, tada pirma eilutė yra didesnį (ar mažesnė) už antrąją. Pabaiga.
49
+
2. Jeigu pirmas ženklas iš pirmos eilutės yra didesnis (ar mažesnis) negu kitos eilutės, tada pirma eilutė yra didesnė (ar mažesnė) už antrąją. Pabaiga.
50
50
3. Kitu atveju, jeigu abiejų eilučių pirmi ženklai yra vienodi, tada lyginami antri ženklai tuo pačiu principu.
51
51
4. Pakartoti iki vienos iš eilučių pabaigos.
52
-
5. Jeigu abi eilutės baigiasi tuo pačiu metu, jos yra vienodo. Kitu atveju ilgesnė eilutė yra didesnė.
52
+
5. Jeigu abi eilutės baigiasi tuo pačiu metu, jos yra vienodos. Kitu atveju ilgesnė eilutė yra didesnė.
53
53
54
54
Pavyzdyje aukščiau, palyginimas `'Z' > 'A'` gauna atsakymą pirmame žingsnyje, kai tuo tarpu `"Glow"` ir `"Glee"` yra lyginami ženklas po ženklo:
3.`o` yra didesnis nei `e`. Čia sustojame. Pirma eilutė yra didesnė.
59
59
60
60
```smart header="Ne tikras žodynas, bet Unicode eiliškumas"
61
-
Palyginimo algorimtas esantis aukščiau yra maždaug panašus į tokį koks naudojamas žodynuose ir telefonų knygoje, tačiau jis nėra visiškai toks pats.
61
+
Palyginimo algoritmas esantis aukščiau yra maždaug panašus į tokį koks naudojamas žodynuose ir telefonų knygoje, tačiau jis nėra visiškai toks pats.
62
62
63
63
Pavyzdžiui svarbu ar raidės yra mažosios ar didžiosios. Didžioji raidė `"A"` nėra lygi mažajai raidei `"a"`. Kuri yra didesnė? Mažoji `"a"`. Kodėl? Nes mažosios raidės turi aukštesnį indeksą vidinėje JavaScript kodavimo lentelėje (Unicode). Mes sugrįšime prie specifinių detalių ir pasekmių skyriuje <info:string>.
64
64
```
@@ -138,72 +138,72 @@ Griežtos lygybės operatorius yra ilgesnis, bet jis padeda kodui atrodyti aišk
138
138
139
139
## Palyginimai su null ir undefined
140
140
141
-
There's a non-intuitive behavior when `null`or`undefined` are compared to other values.
141
+
Kai lyginami`null`ar`undefined`su kitomis vertėmis elgesys nėra intuityvus.
142
142
143
-
For a strict equality check`===`
144
-
: These values are different, because each of them is a different type.
143
+
Griežtos lygybės patikrinime`===`
144
+
: Šios vertės yra skirtingos, nes kiekviena jų yra skirtingo tipo.
145
145
146
146
```js run
147
147
alert( null === undefined ); // false
148
148
```
149
149
150
-
For a non-strict check`==`
151
-
: There's a special rule. These two are a "sweet couple": they equal each other (in the sense of `==`), but not any other value.
150
+
Negriežtos lygybės patikrai`==`
151
+
: Yra speciali taisyklė. Šie du yra "saldi porelė": jie yra lygūs vienas kitam (kai yra `==`), bet jokioms kitoms vertėms.
152
152
153
153
```js run
154
154
alert( null == undefined ); // true
155
155
```
156
156
157
-
For maths and other comparisons`< > <= >=`
158
-
: `null/undefined`are converted to numbers: `null`becomes`0`, while `undefined`becomes`NaN`.
157
+
Matematiniuose ir kitokiuose palyginimuose`< > <= >=`
158
+
: `null/undefined`yra paverčiami skaičiais: `null`tampa`0`, tuo tarpu `undefined`tampa`NaN`.
159
159
160
-
Now let's see some funny things that happen when we apply these rules. And, what's more important, how to not fall into a trap with them.
160
+
Dabar pasižiūrėkime į juokingus atvejus kai šios taisyklės būna pritaikomos. Ir visų svarbiausia kaip dėl jų nepakliūti į spąstus.
161
161
162
-
### Strange result: null vs 0
162
+
### Keistas rezultatas: null vs 0
163
163
164
-
Let's compare `null`with a zero:
164
+
Palyginkime `null`su nuliu:
165
165
166
166
```js run
167
167
alert( null>0 ); // (1) false
168
168
alert( null==0 ); // (2) false
169
169
alert( null>=0 ); // (3) *!*true*/!*
170
170
```
171
171
172
-
Mathematically, that's strange. The last result states that "`null`is greater than or equal to zero", so in one of the comparisons above it must be`true`, but they are both false.
172
+
Tai labai keista matematiškai. Rezultatas sako, kad "`null`yra didesnis arba lygus nuliu", vadinasi viename iš aukščiau esančių palyginimų turėtų būti taip pat`true`, bet jie abu yra neteisingi.
173
173
174
-
The reason is that an equality check`==`and comparisons`> < >= <=`work differently. Comparisons convert`null`to a number, treating it as`0`. That's why (3) `null >= 0`is true and (1) `null > 0`is false.
174
+
To priežastis yra tai, kad lygybės patikrinimas`==`ir palyginimai`> < >= <=`veikia kitaip. Palyginimai paverčia`null`į skaičių ir laiko jį nuliu`0`. Štai dėl ko (3) `null >= 0`yra tiesa, o `null > 0`yra netiesa.
175
175
176
-
On the other hand, the equality check `==`for `undefined`and`null`is defined such that, without any conversions, they equal each other and don't equal anything else. That's why (2) `null == 0`is false.
176
+
Iš kitos pusės, lygybės patikrinimas `==`kaip jau yra apibūdinta, `undefined`ir`null`kai jie nėra konvertuojami, jie yra vienas kitam lygūs, bet nelygūs niekam kitam. Štai kodėl (2) `null == 0`yra netiesa.
177
177
178
-
### An incomparable undefined
178
+
### Nepalyginimasis undefined
179
179
180
-
The value `undefined`shouldn't be compared to other values:
180
+
Vertė `undefined`neturėtų būti lyginima su kitomis vertėmis:
181
181
182
182
```js run
183
183
alert( undefined>0 ); // false (1)
184
184
alert( undefined<0 ); // false (2)
185
185
alert( undefined==0 ); // false (3)
186
186
```
187
187
188
-
Why does it dislike zero so much? Always false!
188
+
Kodėl jis taip nemėgsta nulio? Visada netiesa!
189
189
190
-
We get these results because:
190
+
Gauname tokius rezultatas, nes:
191
191
192
-
-Comparisons`(1)`and`(2)`return`false` because`undefined`gets converted to `NaN` and`NaN`is a special numeric value which returns `false` for all comparisons.
193
-
-The equality check `(3)`returns`false` because`undefined`only equals `null`, `undefined`, and no other value.
192
+
-Palyginimai`(1)`ir`(2)`grąžina`false`, nes`undefined`paverčiamas į `NaN`, o`NaN`yra ypatinga skaitinė vertė, kuri visoms vertėms grąžina `false`.
193
+
-Lygybės patikrinimas `(3)`grąžina`false`, nes`undefined`yra lygus tik `null`, `undefined` ir jokiai kitai vertei.
194
194
195
-
### Evade problems
195
+
### Išvenkite problemų
196
196
197
-
Why did we go over these examples? Should we remember these peculiarities all the time? Well, not really. Actually, these tricky things will gradually become familiar over time, but there's a solid way to evade problems with them:
197
+
Kodėl mes peržiūrėjome tokius pavyzdžius? Ar turėtume tokias keistenybes visada prisiminti? Nebūtinai. Tiesą sakant tokie triukai taps pažįstamais su laiku, bet yra būdas kaip išvengti su jais susijusių problemų:
198
198
199
-
Just treat any comparison with `undefined/null`except the strict equality `===` with exceptional care.
199
+
Kiekvieną palyginimą susijusį su `undefined/null`vertinkite atsargiai, išskyrus su griežta lygybe `===`.
200
200
201
-
Don't use comparisons `>= > < <=`with a variable which may be `null/undefined`, unless you're really sure of what you're doing. If a variable can have these values, check for them separately.
201
+
Nenaudokite palyginimų `>= > < <=`su kintamuoju, kuris gali būti `null/undefined`, nebent tikrai žinote ką darote. Jeigu kintamasis gali turėti tokias vertybes, patikrinkite jas atskirai.
202
202
203
-
## Summary
203
+
## Santrauka
204
204
205
-
-Comparison operators return a boolean value.
206
-
-Strings are compared letter-by-letter in the "dictionary" order.
207
-
-When values of different types are compared, they get converted to numbers (with the exclusion of a strict equality check).
208
-
-The values `null`and`undefined`equal `==`each other and do not equal any other value.
209
-
-Be careful when using comparisons like `>`or`<`with variables that can occasionally be `null/undefined`. Checking for `null/undefined`separately is a good idea.
205
+
-Palyginimų operatoriai grąžina loginę vertę.
206
+
-Eilutės yra tikrinamos paraidžiui "žodynėlio" eiliškumo principu.
207
+
-Kai lyginamos skirtingų tipų vertės, jos yra paverčiamos į skaičius (išskyrus tik griežtą lygybės patikrinimą).
208
+
-Vertės `null`ir`undefined`yra lygios `==`viena kitai, bet nelygios jokiai kitai vertei.
209
+
-Būkite atsargūs kai naudojate tokius palyginimus kaip `>`arba`<`su kintamaisiai, kurie laikas nuo laiko gali būti `null/undefined`. Gera mintis yra patikrinti `null/undefined`atskirai.
0 commit comments