Skip to content

Commit fe146ae

Browse files
authored
Update article.md
1 parent 22897b0 commit fe146ae

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

1-js/02-first-steps/08-comparison/article.md

Lines changed: 58 additions & 58 deletions
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. Matematikos 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 atvejuta 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 vienodo. 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 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.
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,42 +101,42 @@ 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

141141
There's a non-intuitive behavior when `null` or `undefined` are compared to other values.
142142

0 commit comments

Comments
 (0)