From fb50a432bcf2955ff99db9e410d85b0f315a3eb8 Mon Sep 17 00:00:00 2001 From: bartek7 Date: Sun, 14 Jul 2019 16:17:19 +0200 Subject: [PATCH 1/4] Translated conversion into PL --- .../solution.md | 12 +- .../1-primitive-conversions-questions/task.md | 8 +- .../06-type-conversions/article.md | 118 +++++++++--------- 3 files changed, 69 insertions(+), 69 deletions(-) diff --git a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md index 7dd0d61c2..e103fa5e3 100644 --- a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md +++ b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md @@ -16,9 +16,9 @@ null + 1 = 1 // (5) undefined + 1 = NaN // (6) ``` -1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied. -2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`. -3. The addition with a string appends the number `5` to the string. -4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it). -5. `null` becomes `0` after the numeric conversion. -6. `undefined` becomes `NaN` after the numeric conversion. +1. Dodawanie stringa `"" + 1` konwertuje `1` do stringa: `"" + 1 = "1"` i wtedy mamy zastosowane `"1" + 0`. +2. Odejmowanie `-` (jak większość matematycznych operacji) działa wyłącznie z typami liczbowymi i konwertuje pusty string `""` do `0`. +3. Dodawanie stringa dołącza liczbę `5` do tego stringa. +4. Odejmowanie zawsze konwertuje do liczby, zatem konwertuje `" -9 "` na typ number `-9` (ignoruje spacje dookoła). +5. `null` stanie się `0` po konwersji na liczbę. +6. `undefined` stanie się `NaN` po konwersji na liczbę. diff --git a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md index f17e870de..0423fdebc 100644 --- a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md +++ b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md @@ -1,10 +1,10 @@ -importance: 5 +Ważność: 5 --- -# Type conversions +# Konwersje typów -What are results of these expressions? +Jakie będą rezultaty poniższych wyrażeń? ```js no-beautify "" + 1 + 0 @@ -23,4 +23,4 @@ null + 1 undefined + 1 ``` -Think well, write down and then compare with the answer. +Pomyśl dobrze, zapisz odpowiedzi i porównaj z prawidłowym rozwiązaniem. \ No newline at end of file diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index 6ac695e84..859fc11da 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -1,111 +1,111 @@ -# Type Conversions +# Konwersje typów -Most of the time, operators and functions automatically convert the values given to them to the right type. +W większości przypadków operatory i funkcje automatycznie konwertują przekazywane do nich wartości na właściwy typ. -For example, `alert` automatically converts any value to a string to show it. Mathematical operations convert values to numbers. +Na przykład `alert` automatycznie zmieni typ dowolnej wartości do stringa. Matematyczne operacje konwertują wartości do typu liczbowego. -There are also cases when we need to explicitly convert a value to the expected type. +Istnieją jednak przypadku, w których musimy jawne zmienić typ wartości na inny. -```smart header="Not talking about objects yet" -In this chapter, we won't cover objects. Instead, we'll study primitives first. Later, after we learn about objects, we'll see how object conversion works in the chapter . +```smart header="Nie mówimy jeszcze o obiektach" +W tym rozdziale nie zajmujemy się objektami. In this chapter, we won't cover objects. Zamiast tego nauczymy się najpierw typów prymitywnych. Później nauczymy się co nieco o obiektach i zobaczymy jak działa konwersja obiektów w rozdziale . ``` -## ToString +## ToString (do stringa) -String conversion happens when we need the string form of a value. +Konwersja do stringa następuje kiedy potrzebujemy wartości typu string. -For example, `alert(value)` does it to show the value. +Na przykład `alert(value)` konwertuje do stringa żeby wyświetlić wartość. -We can also call the `String(value)` function to convert a value to a string: +Możemy również wywołać funkcję `String(value)` żeby skonwertować wartość: ```js run let value = true; alert(typeof value); // boolean *!* -value = String(value); // now value is a string "true" +value = String(value); // teraz wartość "true" jest stringiem alert(typeof value); // string */!* ``` -String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc. +Konwersja stringów jest bardzo przewidywalna. `false` zostaje `"false"`, typ boolean `null` jest stringiem `"null"`, etc. -## ToNumber +## ToNumber (do liczby) -Numeric conversion happens in mathematical functions and expressions automatically. +Konwersja do typu liczbowego następuje automatycznie w wyniku matematycznych wyrażeń i funkcji. -For example, when division `/` is applied to non-numbers: +Na przykład dzielenie `/` dla wartości nie będących liczbami: ```js run -alert( "6" / "2" ); // 3, strings are converted to numbers +alert( "6" / "2" ); // 3, stringi są zamienione na liczby ``` -We can use the `Number(value)` function to explicitly convert a `value` to a number: +Możemy użyć funkcji `Number(value)`, aby jawnie przekonwertować `wartość` do liczby. ```js run let str = "123"; alert(typeof str); // string -let num = Number(str); // becomes a number 123 +let num = Number(str); // zostaje typem liczbowym o wartości 123 alert(typeof num); // number ``` -Explicit conversion is usually required when we read a value from a string-based source like a text form but expect a number to be entered. +Jawna konwersja jest zazwyczaj wymagana gdy chcemy odczytać wartość ze źródła będącą stringiem, a oczekujemy wartości liczbowej. -If the string is not a valid number, the result of such a conversion is `NaN`. For instance: +Jeśli string nie jest prawidłową liczbą wynikiem konwersji będzie `NaN`. Dla przykładu: ```js run -let age = Number("an arbitrary string instead of a number"); +let age = Number("dowolny ciąg znaków zamiast typu liczbowego"); -alert(age); // NaN, conversion failed +alert(age); // NaN, konwersja nie powiodła się ``` -Numeric conversion rules: +Zasady konwersji typu liczbowego: -| Value | Becomes... | -|-------|-------------| +| Wartość | Otrzymamy... | +|---------|-------------| |`undefined`|`NaN`| |`null`|`0`| |true and false | `1` and `0` | -| `string` | Whitespaces from the start and end are removed. If the remaining string is empty, the result is `0`. Otherwise, the number is "read" from the string. An error gives `NaN`. | +| `string` | Białe znaki z początku i końca są usunięte. Jeśli pozostała wartość stringa jest pusta wynikiem będzie `0`. W przeciwnym wypadku liczba jest odczytywana ze stringa. Wszystkie nieprawidłowe konwersje dają `NaN`. | -Examples: +Przykłady: ```js run alert( Number(" 123 ") ); // 123 -alert( Number("123z") ); // NaN (error reading a number at "z") +alert( Number("123z") ); // NaN (błąd podczas odczytywania liczby ze stringa "z") alert( Number(true) ); // 1 alert( Number(false) ); // 0 ``` -Please note that `null` and `undefined` behave differently here: `null` becomes zero while `undefined` becomes `NaN`. +Zauważ, że `null` i `undefined` zachowują się inaczej. `null` zostanie przekonwertowany do zera, natomiast `undefined` sprawi, że wynikiem będzie `NaN`. -````smart header="Addition '+' concatenates strings" -Almost all mathematical operations convert values to numbers. A notable exception is addition `+`. If one of the added values is a string, the other one is also converted to a string. +````smart header="'+' konkatenuje stringi" +Większość matematycznych operacji konwertuje wartości do typu liczbowego. Jedynym wyjątkiem jest `+`. Jeśli dodasz jedną z wartości, która będzie stringiem, wtedy wynikiem takiej operacji będzie typ string. -Then, it concatenates (joins) them: +Wtedy operacja je konkatenuje (łączy): ```js run -alert( 1 + '2' ); // '12' (string to the right) -alert( '1' + 2 ); // '12' (string to the left) +alert( 1 + '2' ); // '12' (string po prawej) +alert( '1' + 2 ); // '12' (string po lewej) ``` -This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers. +Dzieje się to w przypadku gdy przynajmniej jeden z argumentów jest stringiem. W przeciwnym wypadku wartości zostaną przekonwertowane na typ liczbowy. ```` ## ToBoolean -Boolean conversion is the simplest one. +Konwersje typu Boolean są najprostsze. -It happens in logical operations (later we'll meet condition tests and other similar things) but can also be performed explicitly with a call to `Boolean(value)`. +Zachodzą w logicznych operacjach (później poznamy warunki i inne podobne rzeczy) i może zostać wywołana z użyciem funkcji `Boolean(value)`. -The conversion rule: +Zasada konwersji: -- Values that are intuitively "empty", like `0`, an empty string, `null`, `undefined`, and `NaN`, become `false`. -- Other values become `true`. +- Wartości, które są "puste" np. `0`, pusty string, `null`, `undefined` i `NaN` zostaną przekonwertowane do `false`. +- Inne wartości zostaną przekonwertowane do `true`. -For instance: +Na przykład: ```js run alert( Boolean(1) ); // true @@ -115,46 +115,46 @@ alert( Boolean("hello") ); // true alert( Boolean("") ); // false ``` -````warn header="Please note: the string with zero `\"0\"` is `true`" -Some languages (namely PHP) treat `"0"` as `false`. But in JavaScript, a non-empty string is always `true`. +````warn header="Miej na uwadze, że string z `\"0\"` będzie `true`" +Niektóre języki (np. PHP) traktują `"0"` jako `false`. Ale w JavaScript każdy string z jakąkolwiek wartością jest zawsze `true`. ```js run alert( Boolean("0") ); // true -alert( Boolean(" ") ); // spaces, also true (any non-empty string is true) +alert( Boolean(" ") ); // spacje, również true (jakakolwiek wartość stringowa jest true) ``` ```` -## Summary +## Podsumowanie -The three most widely used type conversions are to string, to number, and to boolean. +Trzy najczęściej używane konwersje dotyczą konwersji do stringu, liczby i typu boolean. -**`ToString`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values. +**`ToString`** -- Zachodzi gdy coś wpisujemy. Może zajść również z użyciem `String(value)`. Konwersja do stringa jest zazwyczaj oczywista dla prymitywnych wartości. -**`ToNumber`** -- Occurs in math operations. Can be performed with `Number(value)`. +**`ToNumber`** -- Zachodzi w matematycznych operacjach. Może zajść również z użyciem `Number(value)`. -The conversion follows the rules: +Konwersja jest zgodna z zasadami: -| Value | Becomes... | +| Wartość | Otrzymamy... | |-------|-------------| |`undefined`|`NaN`| |`null`|`0`| |true / false | `1 / 0` | -| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. | +| `string` | String jest odczytywany taki "jak jest", białe znaki z obu stron są zignorowane. Pusty string staje się `0`. Błąd konwersji zwraca `NaN`.| -**`ToBoolean`** -- Occurs in logical operations. Can be performed with `Boolean(value)`. +**`ToBoolean`** -- Zachodzi w logicznych operacjach. Może zajść również z użyciem `Boolean(value)`. -Follows the rules: +Konwersja jest zgodna z zasadami: -| Value | Becomes... | +| Wartość | Otrzymamy... | |-------|-------------| |`0`, `null`, `undefined`, `NaN`, `""` |`false`| -|any other value| `true` | +|Każda inna wartość| `true` | -Most of these rules are easy to understand and memorize. The notable exceptions where people usually make mistakes are: +Większość z tych zasad jest łatwa do zrozumienia i zapamiętania. Most of these rules are easy to understand and memorize. Wyjątki, które warto wspomnieć, w których ludzie najczęściej popełniają błędy:Warte uwagi najczęściej popełnianie błędy: -- `undefined` is `NaN` as a number, not `0`. -- `"0"` and space-only strings like `" "` are true as a boolean. +- `undefined` to `NaN` jako number, a nie `0`. +- `"0"` i spacja w stringu np. `" "` będzie true jako boolean. -Objects aren't covered here. We'll return to them later in the chapter that is devoted exclusively to objects after we learn more basic things about JavaScript. +Objekty nie są tutaj omówione. Wrócimy do nich później w rozdziale , który jest poświęcony obiektom, gdy poznamy już więcej podstaw JavaScript. \ No newline at end of file From 2acb601ee17ed4532d48c301e118da5de8faad57 Mon Sep 17 00:00:00 2001 From: bartek7 Date: Tue, 23 Jul 2019 08:18:58 +0200 Subject: [PATCH 2/4] fixes typos and clean up the text --- .../1-primitive-conversions-questions/task.md | 2 +- .../06-type-conversions/article.md | 6 +- 1-js/02-first-steps/08-comparison/article.md | 93 ++++++++++--------- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md index 0423fdebc..9c16b43f7 100644 --- a/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md +++ b/1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md @@ -1,4 +1,4 @@ -Ważność: 5 +importance: 5 --- diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index 859fc11da..f2dfb08b5 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -4,10 +4,10 @@ W większości przypadków operatory i funkcje automatycznie konwertują przekaz Na przykład `alert` automatycznie zmieni typ dowolnej wartości do stringa. Matematyczne operacje konwertują wartości do typu liczbowego. -Istnieją jednak przypadku, w których musimy jawne zmienić typ wartości na inny. +Istnieją jednak przypadki, w których musimy jawnie zmienić typ wartości na inny. ```smart header="Nie mówimy jeszcze o obiektach" -W tym rozdziale nie zajmujemy się objektami. In this chapter, we won't cover objects. Zamiast tego nauczymy się najpierw typów prymitywnych. Później nauczymy się co nieco o obiektach i zobaczymy jak działa konwersja obiektów w rozdziale . +W tym rozdziale nie zajmujemy się objektami. Zamiast tego nauczymy się najpierw typów prymitywnych. Później nauczymy się co nieco o obiektach i zobaczymy jak działa konwersja obiektów w rozdziale . ``` ## ToString (do stringa) @@ -28,7 +28,7 @@ alert(typeof value); // string */!* ``` -Konwersja stringów jest bardzo przewidywalna. `false` zostaje `"false"`, typ boolean `null` jest stringiem `"null"`, etc. +Konwersja stringów jest bardzo przewidywalna. `false` zostaje `"false"`, typ boolean `null` staje się stringiem `"null"`, etc. ## ToNumber (do liczby) diff --git a/1-js/02-first-steps/08-comparison/article.md b/1-js/02-first-steps/08-comparison/article.md index 8697076a4..5056dbba9 100644 --- a/1-js/02-first-steps/08-comparison/article.md +++ b/1-js/02-first-steps/08-comparison/article.md @@ -1,95 +1,96 @@ -# Comparisons +# Porównania -We know many comparison operators from maths: +Na matematyce poznaliśmy porównania: -- Greater/less than: a > b, a < b. -- Greater/less than or equals: a >= b, a <= b. -- Equals: `a == b` (please note the double equals sign `=`. A single symbol `a = b` would mean an assignment). -- Not equals. In maths the notation is , but in JavaScript it's written as an assignment with an exclamation sign before it: a != b. +- Większe/mniejsze niż: a > b, a < b. +- Większe/mniejsze niż lub równe: a >= b, a <= b. +- Równe: `a == b` (zauważ, że jest tutaj podwójny znak `=`. Pojedyncze użycie `a = b` oznacza przypisanie). +- Nierówne. W matematyce zapiszemy to jako , ale w JavaScript jest to zapisane jako wykrzyknik przed znakiem równości: a != b. -## Boolean is the result +## Wynikiem jest Boolean -Like all other operators, a comparison returns a value. In this case, the value is a boolean. +Jak wszystkie inne operatory porównanie zwraca wartość. W tym przypadku wartością jest Boolean. - `true` -- means "yes", "correct" or "the truth". - `false` -- means "no", "wrong" or "not the truth". -For example: +Na przykład: ```js run -alert( 2 > 1 ); // true (correct) -alert( 2 == 1 ); // false (wrong) -alert( 2 != 1 ); // true (correct) +alert( 2 > 1 ); // true (prawda) +alert( 2 == 1 ); // false (fałsz) +alert( 2 != 1 ); // true (prawda) ``` -A comparison result can be assigned to a variable, just like any value: +Wynik porównania może być przypisany do zmiennej, jak każda inna wartość: ```js run -let result = 5 > 4; // assign the result of the comparison +let result = 5 > 4; // przypisz wynik porównania alert( result ); // true ``` -## String comparison +## Porównanie stringów -To see whether a string is greater than another, JavaScript uses the so-called "dictionary" or "lexicographical" order. +Aby zobaczyć czy ciąg znaków jest większy niż inny JavaScript używa porównania, które nazywamy "słownikowym" lub "leksykograficznym". -In other words, strings are compared letter-by-letter. +Innymi słowy, stringi porównywane są litera po literze. -For example: +Na przykład: ```js run alert( 'Z' > 'A' ); // true -alert( 'Glow' > 'Glee' ); // true -alert( 'Bee' > 'Be' ); // true +alert( 'Brat' > 'Brak' ); // true +alert( 'Jan' > 'Ja' ); // true ``` -The algorithm to compare two strings is simple: +Algorytm porównuje dwa stringi w prosty sposób: -1. Compare the first character of both strings. -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. -3. Otherwise, if both strings' first characters are the same, compare the second characters the same way. -4. Repeat until the end of either string. -5. If both strings end at the same length, then they are equal. Otherwise, the longer string is greater. +1. Porównaj pierwszy znak w obu stringach. +2. Jeśli pierwszy znak w pierwszym stringu jest większy (lub mniejszy) niż inny string, wtedy pierwszy string jest większy (lub mniejszy). Porównanie zakończone. +3. Jeśli pierwsze znaki są takie same zrób porównanie dla kolejnego znaku w ten sam sposób jak w punkcie nr 2. +4. Powtarzaj dopóki nie dojdzie do końca stringu. +5. Jeśli oba stringi mają taką samą długość są równe. W przeciwnym przypadku dłuższy string jest większy. -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: +W powyższych przypadkach porównanie `'Z' > 'A'` zwróci rezultat w pierwszym podejściu. Porównanie `"Brat"` z `"Brak"` będzie porównywane znak po znaku: -1. `G` is the same as `G`. -2. `l` is the same as `l`. -3. `o` is greater than `e`. Stop here. The first string is greater. +1. `B` jest takie same jak `B`. +2. `r` jest takie same jak `r`. +3. `a` jest takie same jak `a`. +3. `t` jest większe niż `k`. Zatrzymaj tutaj. Pierwszy string jest większy. -```smart header="Not a real dictionary, but Unicode order" -The comparison algorithm given above is roughly equivalent to the one used in dictionaries or phone books, but it's not exactly the same. +```smart header="Nie do końca słownikowa, bo kolejność wg Unicode" +Podany powyżej przykład jest prawie taki sam jak algorytm używany w słownikach lub książkach telefonicznych. Ale nie jest dokładnie taki sam. -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 . +Na przykład wielkość ma znaczenie. Duża litera `"A"` nie jest równa małej literze `"a"`. Która jest większa? Mała litera `"a"`. Dlaczego? Ponieważ małe litery mają większy index w wewnętrznej tabeli kodowania znaków (Unicode), której używa JavaScript. Wrócimy do tego w rozdziale . ``` -## Comparison of different types +## Porównania wartości różnego typu -When comparing values of different types, JavaScript converts the values to numbers. +Kiedy porównujemy wartości różnego typu JavaScript konwertuje te wartości na liczby. -For example: +Na przykład: ```js run -alert( '2' > 1 ); // true, string '2' becomes a number 2 -alert( '01' == 1 ); // true, string '01' becomes a number 1 +alert( '2' > 1 ); // true, string '2' staje się numerem 2 +alert( '01' == 1 ); // true, string '01' staje się numerem 1 ``` -For boolean values, `true` becomes `1` and `false` becomes `0`. +Dla wartości Boolean `true` staje się `1`, a `false` staje się `0`. -For example: +Na przykład: ```js run alert( true == 1 ); // true alert( false == 0 ); // true ``` -````smart header="A funny consequence" -It is possible that at the same time: +````smart header="Zabawna zależność" +Jest możliwe, aby w tym samym czasie: -- Two values are equal. -- One of them is `true` as a boolean and the other one is `false` as a boolean. +- Dwie wartości były równe. +- Jedna z nich będzie `true` jako Boolean, natomiast druga jest `false` jako Boolean. -For example: +Na przykład: ```js run let a = 0; @@ -101,7 +102,7 @@ alert( Boolean(b) ); // true alert(a == b); // true! ``` -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. +Z punkty widzenia JavaScript taki rezultat jest oczekiwany i normalny. Porównanie konwertuje wartości na typ liczbowy (więc string `"0"` zostaje `0`), podczas gdy porównanie `Boolean` konwertuje te wartości w inny sposób. ```` ## Strict equality From 9a0202954472744d718239e99f524a5484fb4007 Mon Sep 17 00:00:00 2001 From: bartek7 Date: Tue, 23 Jul 2019 08:20:31 +0200 Subject: [PATCH 3/4] fix funny 'objekt' in polish --- 1-js/02-first-steps/06-type-conversions/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index f2dfb08b5..f763cf9a1 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -7,7 +7,7 @@ Na przykład `alert` automatycznie zmieni typ dowolnej wartości do stringa. Mat Istnieją jednak przypadki, w których musimy jawnie zmienić typ wartości na inny. ```smart header="Nie mówimy jeszcze o obiektach" -W tym rozdziale nie zajmujemy się objektami. Zamiast tego nauczymy się najpierw typów prymitywnych. Później nauczymy się co nieco o obiektach i zobaczymy jak działa konwersja obiektów w rozdziale . +W tym rozdziale nie zajmujemy się obiektami. Zamiast tego nauczymy się najpierw typów prymitywnych. Później nauczymy się co nieco o obiektach i zobaczymy jak działa konwersja obiektów w rozdziale . ``` ## ToString (do stringa) @@ -157,4 +157,4 @@ Większość z tych zasad jest łatwa do zrozumienia i zapamiętania. Most of th - `undefined` to `NaN` jako number, a nie `0`. - `"0"` i spacja w stringu np. `" "` będzie true jako boolean. -Objekty nie są tutaj omówione. Wrócimy do nich później w rozdziale , który jest poświęcony obiektom, gdy poznamy już więcej podstaw JavaScript. \ No newline at end of file +Obiekty nie są tutaj omówione. Wrócimy do nich później w rozdziale , który jest poświęcony obiektom, gdy poznamy już więcej podstaw JavaScript. \ No newline at end of file From 2374b9e72991f334cd0a301b085733cdfd46f671 Mon Sep 17 00:00:00 2001 From: bartek7 Date: Tue, 23 Jul 2019 10:58:53 +0200 Subject: [PATCH 4/4] revert changes with another translation in another file --- .../06-type-conversions/article.md | 1 - 1-js/02-first-steps/08-comparison/article.md | 93 +++++++++---------- 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/1-js/02-first-steps/06-type-conversions/article.md b/1-js/02-first-steps/06-type-conversions/article.md index f763cf9a1..464285b40 100644 --- a/1-js/02-first-steps/06-type-conversions/article.md +++ b/1-js/02-first-steps/06-type-conversions/article.md @@ -8,7 +8,6 @@ Istnieją jednak przypadki, w których musimy jawnie zmienić typ wartości na i ```smart header="Nie mówimy jeszcze o obiektach" W tym rozdziale nie zajmujemy się obiektami. Zamiast tego nauczymy się najpierw typów prymitywnych. Później nauczymy się co nieco o obiektach i zobaczymy jak działa konwersja obiektów w rozdziale . -``` ## ToString (do stringa) diff --git a/1-js/02-first-steps/08-comparison/article.md b/1-js/02-first-steps/08-comparison/article.md index 5056dbba9..8697076a4 100644 --- a/1-js/02-first-steps/08-comparison/article.md +++ b/1-js/02-first-steps/08-comparison/article.md @@ -1,96 +1,95 @@ -# Porównania +# Comparisons -Na matematyce poznaliśmy porównania: +We know many comparison operators from maths: -- Większe/mniejsze niż: a > b, a < b. -- Większe/mniejsze niż lub równe: a >= b, a <= b. -- Równe: `a == b` (zauważ, że jest tutaj podwójny znak `=`. Pojedyncze użycie `a = b` oznacza przypisanie). -- Nierówne. W matematyce zapiszemy to jako , ale w JavaScript jest to zapisane jako wykrzyknik przed znakiem równości: a != b. +- Greater/less than: a > b, a < b. +- Greater/less than or equals: a >= b, a <= b. +- Equals: `a == b` (please note the double equals sign `=`. A single symbol `a = b` would mean an assignment). +- Not equals. In maths the notation is , but in JavaScript it's written as an assignment with an exclamation sign before it: a != b. -## Wynikiem jest Boolean +## Boolean is the result -Jak wszystkie inne operatory porównanie zwraca wartość. W tym przypadku wartością jest Boolean. +Like all other operators, a comparison returns a value. In this case, the value is a boolean. - `true` -- means "yes", "correct" or "the truth". - `false` -- means "no", "wrong" or "not the truth". -Na przykład: +For example: ```js run -alert( 2 > 1 ); // true (prawda) -alert( 2 == 1 ); // false (fałsz) -alert( 2 != 1 ); // true (prawda) +alert( 2 > 1 ); // true (correct) +alert( 2 == 1 ); // false (wrong) +alert( 2 != 1 ); // true (correct) ``` -Wynik porównania może być przypisany do zmiennej, jak każda inna wartość: +A comparison result can be assigned to a variable, just like any value: ```js run -let result = 5 > 4; // przypisz wynik porównania +let result = 5 > 4; // assign the result of the comparison alert( result ); // true ``` -## Porównanie stringów +## String comparison -Aby zobaczyć czy ciąg znaków jest większy niż inny JavaScript używa porównania, które nazywamy "słownikowym" lub "leksykograficznym". +To see whether a string is greater than another, JavaScript uses the so-called "dictionary" or "lexicographical" order. -Innymi słowy, stringi porównywane są litera po literze. +In other words, strings are compared letter-by-letter. -Na przykład: +For example: ```js run alert( 'Z' > 'A' ); // true -alert( 'Brat' > 'Brak' ); // true -alert( 'Jan' > 'Ja' ); // true +alert( 'Glow' > 'Glee' ); // true +alert( 'Bee' > 'Be' ); // true ``` -Algorytm porównuje dwa stringi w prosty sposób: +The algorithm to compare two strings is simple: -1. Porównaj pierwszy znak w obu stringach. -2. Jeśli pierwszy znak w pierwszym stringu jest większy (lub mniejszy) niż inny string, wtedy pierwszy string jest większy (lub mniejszy). Porównanie zakończone. -3. Jeśli pierwsze znaki są takie same zrób porównanie dla kolejnego znaku w ten sam sposób jak w punkcie nr 2. -4. Powtarzaj dopóki nie dojdzie do końca stringu. -5. Jeśli oba stringi mają taką samą długość są równe. W przeciwnym przypadku dłuższy string jest większy. +1. Compare the first character of both strings. +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. +3. Otherwise, if both strings' first characters are the same, compare the second characters the same way. +4. Repeat until the end of either string. +5. If both strings end at the same length, then they are equal. Otherwise, the longer string is greater. -W powyższych przypadkach porównanie `'Z' > 'A'` zwróci rezultat w pierwszym podejściu. Porównanie `"Brat"` z `"Brak"` będzie porównywane znak po znaku: +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: -1. `B` jest takie same jak `B`. -2. `r` jest takie same jak `r`. -3. `a` jest takie same jak `a`. -3. `t` jest większe niż `k`. Zatrzymaj tutaj. Pierwszy string jest większy. +1. `G` is the same as `G`. +2. `l` is the same as `l`. +3. `o` is greater than `e`. Stop here. The first string is greater. -```smart header="Nie do końca słownikowa, bo kolejność wg Unicode" -Podany powyżej przykład jest prawie taki sam jak algorytm używany w słownikach lub książkach telefonicznych. Ale nie jest dokładnie taki sam. +```smart header="Not a real dictionary, but Unicode order" +The comparison algorithm given above is roughly equivalent to the one used in dictionaries or phone books, but it's not exactly the same. -Na przykład wielkość ma znaczenie. Duża litera `"A"` nie jest równa małej literze `"a"`. Która jest większa? Mała litera `"a"`. Dlaczego? Ponieważ małe litery mają większy index w wewnętrznej tabeli kodowania znaków (Unicode), której używa JavaScript. Wrócimy do tego w rozdziale . +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 . ``` -## Porównania wartości różnego typu +## Comparison of different types -Kiedy porównujemy wartości różnego typu JavaScript konwertuje te wartości na liczby. +When comparing values of different types, JavaScript converts the values to numbers. -Na przykład: +For example: ```js run -alert( '2' > 1 ); // true, string '2' staje się numerem 2 -alert( '01' == 1 ); // true, string '01' staje się numerem 1 +alert( '2' > 1 ); // true, string '2' becomes a number 2 +alert( '01' == 1 ); // true, string '01' becomes a number 1 ``` -Dla wartości Boolean `true` staje się `1`, a `false` staje się `0`. +For boolean values, `true` becomes `1` and `false` becomes `0`. -Na przykład: +For example: ```js run alert( true == 1 ); // true alert( false == 0 ); // true ``` -````smart header="Zabawna zależność" -Jest możliwe, aby w tym samym czasie: +````smart header="A funny consequence" +It is possible that at the same time: -- Dwie wartości były równe. -- Jedna z nich będzie `true` jako Boolean, natomiast druga jest `false` jako Boolean. +- Two values are equal. +- One of them is `true` as a boolean and the other one is `false` as a boolean. -Na przykład: +For example: ```js run let a = 0; @@ -102,7 +101,7 @@ alert( Boolean(b) ); // true alert(a == b); // true! ``` -Z punkty widzenia JavaScript taki rezultat jest oczekiwany i normalny. Porównanie konwertuje wartości na typ liczbowy (więc string `"0"` zostaje `0`), podczas gdy porównanie `Boolean` konwertuje te wartości w inny sposób. +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. ```` ## Strict equality pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy