Skip to content

Commit 90046c1

Browse files
authored
Merge pull request #72 from meilune/master
Translated Comparisons Article
2 parents c1b34d5 + 2a36d36 commit 90046c1

File tree

3 files changed

+97
-97
lines changed

3 files changed

+97
-97
lines changed

1-js/02-first-steps/08-comparison/1-comparison-questions/solution.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ null == "\n0\n" → false
1010
null === +"\n0\n"false
1111
```
1212

13-
Some of the reasons:
13+
Kai kurios priežastys:
1414

15-
1. Obviously, true.
16-
2. Dictionary comparison, hence false.
17-
3. Again, dictionary comparison, first char of `"2"` is greater than the first char of `"1"`.
18-
4. Values `null` and `undefined` equal each other only.
19-
5. Strict equality is strict. Different types from both sides lead to false.
20-
6. Similar to `(4)`, `null` only equals `undefined`.
21-
7. Strict equality of different types.
15+
1. Akivaizdžiai tiesa.
16+
2. Žodynėlio palyginimas, tad netiesa.
17+
3. Vėlgi, žodynėlio palyginimas, tad pirmasis ženklas eilutėje `"2"` yra didenis nei pirmasis ženklas eilutėje `"1"`.
18+
4. Vertės `null` ir `undefined` yra lygios viena kitai.
19+
5. Griežta lygybė yra griežta. Skirtingi tipai abiejose pusėse atveda prie netiesos.
20+
6. Panašiai į `(4)`, `null` yra lygus tik `undefined`.
21+
7. Griežta skirtingų tipų lygybė.

1-js/02-first-steps/08-comparison/1-comparison-questions/task.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 5
22

33
---
44

5-
# Comparisons
5+
# Palyginimai
66

7-
What will be the result for these expressions?
7+
Kokie bus šių išraiškų rezultatai?
88

99
```js no-beautify
1010
5 > 4
+87-87
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,95 @@
1-
# Comparisons
1+
# Palyginimai
22

3-
We know many comparison operators from maths:
3+
Iš matematikos mes žinome daug palyginimo operatorių:
44

5-
- Greater/less than: <code>a &gt; b</code>, <code>a &lt; b</code>.
6-
- Greater/less than or equals: <code>a &gt;= b</code>, <code>a &lt;= b</code>.
7-
- Equals: `a == b` (please note the double equals sign `=`. A single symbol `a = b` would mean an assignment).
8-
- Not equals. In maths the notation is <code>&ne;</code>, but in JavaScript it's written as an assignment with an exclamation sign before it: <code>a != b</code>.
5+
- Daugiau/mažiau negu: <code>a &gt; b</code>, <code>a &lt; b</code>.
6+
- Daugiau/mažiau arba lygu negu: <code>a &gt;= b</code>, <code>a &lt;= b</code>.
7+
- Lygu: `a == b` (atkreipkite dėmesį į dvigubos lygybės ženklą `=`. Vienas ženklas `a = b` reikštų priskyrimą).
8+
- Nelygus. Matematikoje toks ženklas yra <code>&ne;</code>, bet JavaScript jis rašomas kaip asigmentas su šauktuku prieš jį: <code>a != b</code>.
99

10-
## Boolean is the result
10+
## Loginė vertė yra rezultatas
1111

12-
Like all other operators, a comparison returns a value. In this case, the value is a boolean.
12+
Kaip ir visi kiti operatoriai, palyginimas grąžina vertę. Šiuo atveju ta vertė yra loginė.
1313

14-
- `true` -- means "yes", "correct" or "the truth".
15-
- `false` -- means "no", "wrong" or "not the truth".
14+
- `true` -- reiškia "taip", "teisingai" arba "tiesa".
15+
- `false` -- reiškia "ne", "neteisingai" arba "netiesa".
1616

17-
For example:
17+
Pavyzdžiui:
1818

1919
```js run
20-
alert( 2 > 1 ); // true (correct)
21-
alert( 2 == 1 ); // false (wrong)
22-
alert( 2 != 1 ); // true (correct)
20+
alert( 2 > 1 ); // true (teisingai)
21+
alert( 2 == 1 ); // false (neteisingai)
22+
alert( 2 != 1 ); // true (teisingai)
2323
```
2424

25-
A comparison result can be assigned to a variable, just like any value:
25+
Palyginimo rezultatas gali būti priskirtas kintamajam, kaip ir bet kuri kita vertė:
2626

2727
```js run
28-
let result = 5 > 4; // assign the result of the comparison
28+
let result = 5 > 4; // priskirti palyginimo rezultato vertę
2929
alert( result ); // true
3030
```
3131

32-
## String comparison
32+
## Eilutės palyginimas
3333

34-
To see whether a string is greater than another, JavaScript uses the so-called "dictionary" or "lexicographical" order.
34+
Kad patikrintų ar viena eilutė yra didesnė už kitą, JavaScript naudoja taip vadinamą "žodyno" arba "leksikografinį" eiliškumą
3535

36-
In other words, strings are compared letter-by-letter.
36+
Kitais žodžiais, eilutės yra lyginamos paraidžiui.
3737

38-
For example:
38+
Pavyzdžiui:
3939

4040
```js run
4141
alert( 'Z' > 'A' ); // true
4242
alert( 'Glow' > 'Glee' ); // true
4343
alert( 'Bee' > 'Be' ); // true
4444
```
4545

46-
The algorithm to compare two strings is simple:
46+
Algoritmas eilučių palyginimui yra labai paprastas:
4747

48-
1. Compare the first character of both strings.
49-
2. If the first character from the first string is greater (or less) than the other string's, then the first string is greater (or less) than the second. We're done.
50-
3. Otherwise, if both strings' first characters are the same, compare the second characters the same way.
51-
4. Repeat until the end of either string.
52-
5. If both strings end at the same length, then they are equal. Otherwise, the longer string is greater.
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.
50+
3. Kitu atveju, jeigu abiejų eilučių pirmi ženklai yra vienodi, tada lyginami antri ženklai tuo pačiu principu.
51+
4. Pakartoti iki vienos iš eilučių pabaigos.
52+
5. Jeigu abi eilutės baigiasi tuo pačiu metu, jos yra vienodos. Kitu atveju ilgesnė eilutė yra didesnė.
5353

54-
In the examples above, the comparison `'Z' > 'A'` gets to a result at the first step while the strings `"Glow"` and `"Glee"` are compared character-by-character:
54+
Pavyzdyje aukščiau, palyginimas `'Z' > 'A'` gauna atsakymą pirmame žingsnyje, kai tuo tarpu `"Glow"` ir `"Glee"` yra lyginami ženklas po ženklo:
5555

56-
1. `G` is the same as `G`.
57-
2. `l` is the same as `l`.
58-
3. `o` is greater than `e`. Stop here. The first string is greater.
56+
1. `G` tas pats kaip `G`.
57+
2. `l` tas pats kaip `l`.
58+
3. `o` yra didesnis nei `e`. Čia sustojame. Pirma eilutė yra didesnė.
5959

60-
```smart header="Not a real dictionary, but Unicode order"
61-
The comparison algorithm given above is roughly equivalent to the one used in dictionaries or phone books, but it's not exactly the same.
60+
```smart header="Ne tikras žodynas, bet Unicode eiliškumas"
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.
6262
63-
For instance, case matters. A capital letter `"A"` is not equal to the lowercase `"a"`. Which one is greater? The lowercase `"a"`. Why? Because the lowercase character has a greater index in the internal encoding table JavaScript uses (Unicode). We'll get back to specific details and consequences of this in the chapter <info:string>.
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>.
6464
```
6565

66-
## Comparison of different types
66+
## Skirtingų tipų palyginimai
6767

68-
When comparing values of different types, JavaScript converts the values to numbers.
68+
JavaScript lygindama skirtingų tipų vertes, jas paverčia į skaičius.
6969

70-
For example:
70+
Pavyzdžiui:
7171

7272
```js run
73-
alert( '2' > 1 ); // true, string '2' becomes a number 2
74-
alert( '01' == 1 ); // true, string '01' becomes a number 1
73+
alert( '2' > 1 ); // true, eilutė '2' tampa skaičiumi 2
74+
alert( '01' == 1 ); // true, eilutė '01' tampa skaičiumi 1
7575
```
7676

77-
For boolean values, `true` becomes `1` and `false` becomes `0`.
77+
Loginėse vertėse, `true` tampa `1`, o `false` tampa `0`.
7878

79-
For example:
79+
Pavyzdžiui:
8080

8181
```js run
8282
alert( true == 1 ); // true
8383
alert( false == 0 ); // true
8484
```
8585

86-
````smart header="A funny consequence"
87-
It is possible that at the same time:
86+
````smart header="Linksmas sutapimas"
87+
Ar įmanoma, kad tuo pačiu metu:
8888
89-
- Two values are equal.
90-
- One of them is `true` as a boolean and the other one is `false` as a boolean.
89+
- Dvi vertės yra vienodos.
90+
- Kaip loginė vertė viena iš jų yra `true`, o kita yra `false`.
9191
92-
For example:
92+
Pavyzdžiui:
9393
9494
```js run
9595
let a = 0;
@@ -101,109 +101,109 @@ alert( Boolean(b) ); // true
101101
alert(a == b); // true!
102102
```
103103
104-
From JavaScript's standpoint, this result is quite normal. An equality check converts values using the numeric conversion (hence `"0"` becomes `0`), while the explicit `Boolean` conversion uses another set of rules.
104+
JavaScript pozicijos, toks rezultatas yra visiškai normalus. Palyginimas paverčia vertes naudodamas skaičių konversijas (tad `"0"` tampa `0`), o tuo tarpu išskirtinė loginė `Boolean` konversija naudoja kitokias taisykles.
105105
````
106106

107-
## Strict equality
107+
## Griežta lygybė
108108

109-
A regular equality check `==` has a problem. It cannot differentiate `0` from `false`:
109+
Įprastinės lygybės patikrinimas `==` turi problemą. Ji negali atskirti `0` nuo `false`:
110110

111111
```js run
112112
alert( 0 == false ); // true
113113
```
114114

115-
The same thing happens with an empty string:
115+
Tas pats nutinka su tuščia eilutė:
116116

117117
```js run
118118
alert( '' == false ); // true
119119
```
120120

121-
This happens because operands of different types are converted to numbers by the equality operator `==`. An empty string, just like `false`, becomes a zero.
121+
Taip nutinka dėl to, kad skirtingų tipų operandai naudojant lygybės operatorių `==` yra paverčiami į skaičius. Tuščia eilutė, taip pat kaip ir `false`, tampa nuliu.
122122

123-
What to do if we'd like to differentiate `0` from `false`?
123+
Ką daryti jeigu mes norime, kad `0` skirtųsi nuo `false`?
124124

125-
**A strict equality operator `===` checks the equality without type conversion.**
125+
**Griežtos lygybės operatorius `===` patikrina lygybę nedarydamas tipo konversijos.**
126126

127-
In other words, if `a` and `b` are of different types, then `a === b` immediately returns `false` without an attempt to convert them.
127+
Kitaip sakant, jeigu `a` ir `b` yra skirtingų tipų, tada `a === b` iš karto grąžina `false` net nebandydama jų konvertuoti.
128128

129-
Let's try it:
129+
Pabandykime:
130130

131131
```js run
132-
alert( 0 === false ); // false, because the types are different
132+
alert( 0 === false ); // false, nes tipai yra skirtingi
133133
```
134134

135-
There is also a "strict non-equality" operator `!==` analogous to `!=`.
135+
Taip pat yra ir "griežtos nelygybės" operatorius `!==` analogiškas `!=`.
136136

137-
The strict equality operator is a bit longer to write, but makes it obvious what's going on and leaves less room for errors.
137+
Griežtos lygybės operatorius yra ilgesnis, bet jis padeda kodui atrodyti aiškesniu ir palieka mažiau vietos klaidoms.
138138

139-
## Comparison with null and undefined
139+
## Palyginimai su null ir undefined
140140

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

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

146146
```js run
147147
alert( null === undefined ); // false
148148
```
149149

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

153153
```js run
154154
alert( null == undefined ); // true
155155
```
156156

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`.
159159

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

162-
### Strange result: null vs 0
162+
### Keistas rezultatas: null vs 0
163163

164-
Let's compare `null` with a zero:
164+
Palyginkime `null` su nuliu:
165165

166166
```js run
167167
alert( null > 0 ); // (1) false
168168
alert( null == 0 ); // (2) false
169169
alert( null >= 0 ); // (3) *!*true*/!*
170170
```
171171

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

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

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

178-
### An incomparable undefined
178+
### Nepalyginimasis undefined
179179

180-
The value `undefined` shouldn't be compared to other values:
180+
Vertė `undefined` neturėtų būti lyginima su kitomis vertėmis:
181181

182182
```js run
183183
alert( undefined > 0 ); // false (1)
184184
alert( undefined < 0 ); // false (2)
185185
alert( undefined == 0 ); // false (3)
186186
```
187187

188-
Why does it dislike zero so much? Always false!
188+
Kodėl jis taip nemėgsta nulio? Visada netiesa!
189189

190-
We get these results because:
190+
Gauname tokius rezultatas, nes:
191191

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

195-
### Evade problems
195+
### Išvenkite problemų
196196

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ų:
198198

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 `===`.
200200

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

203-
## Summary
203+
## Santrauka
204204

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

Comments
 (0)