Skip to content

Commit b8bdbc2

Browse files
authored
Merge pull request #690 from hexlet-basics/update-logical-negation
update description
2 parents 746039d + 69ca68b commit b8bdbc2

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

modules/45-logic/28-logical-negation/description.en.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ theory: |
1616
1717
I.e., we can just put a `!` to the left of the function call and get the opposite result.
1818
19+
Negation works for any expression. Any value will be cast to the opposite boolean value.
20+
21+
```javascript
22+
const message = 'Hello, world!';
23+
// Works with constants and variables
24+
!message; // false
25+
26+
// And directly with the values
27+
!5; // false
28+
!'hello'; // false
29+
!0; // true
30+
```
31+
1932
Negation is a powerful tool that allows you to concisely express the desired rules in your code without having to write new functions.
2033
2134
What if you wrote `!!isEven(10)` like this? Suddenly, the code would work. Double negation in logic is equivalent to no negation at all.
@@ -26,6 +39,14 @@ theory: |
2639
!!isEven(10); // true
2740
```
2841
42+
Negatives can be inside other expressions.
43+
44+
```javascript
45+
true && !false; // true
46+
!false || false; // true
47+
!!isEven(10) && !'hello'; // false
48+
!!isEven(10) && !!'hello'; // true
49+
2950
instructions: |
3051
3152
1. Write a function, `isPalindrome()`, to check if a word is a palindrome. A palindrome is a word that reads the same backwards as it does forwards.

modules/45-logic/28-logical-negation/description.ru.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@ theory: |
1616
1717
То есть мы просто добавили `!` слева от вызова функции и получили обратное действие.
1818
19+
Отрицание работает для любых выражений. Любое значение будет приведено к противоположному значению логического типа.
20+
21+
```javascript
22+
const message = 'Hello, world!';
23+
// Работает с константами и переменными
24+
!message; // false
25+
26+
// И напрямую со значениями
27+
!5; // false
28+
!'hello'; // false
29+
!0; // true
30+
```
31+
1932
Отрицание — мощный инструмент, который позволяет лаконично выражать задуманные правила в коде без необходимости писать новые функции.
2033
2134
А что если написать так `!!isEven(10)`? Внезапно, но код сработает. В логике двойное отрицание подобно отсутствию отрицания вообще.
@@ -26,6 +39,15 @@ theory: |
2639
!!isEven(10); // true
2740
```
2841
42+
Отрицания могут быть внутри других выражений.
43+
44+
```javascript
45+
true && !false; // true
46+
!false || false; // true
47+
!!isEven(10) && !'hello'; // false
48+
!!isEven(10) && !!'hello'; // true
49+
```
50+
2951
instructions: |
3052
3153
В этом уроке вам нужно будет реализовать две функции `isPalindrome()` и `isNotPalindrome()`

0 commit comments

Comments
 (0)