Skip to content

Rename sum/add functions in examples #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions content/en/2-6-Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,46 @@ function sum(a, b) {
> Named function expression

```js
const max = function max(a, b) {
const sum = function sum(a, b) {
return a + b;
};
```

> Anonymous function expression

```js
const max = function (a, b) {
const sum = function (a, b) {
return a + b;
};
```

> Arrow function (Lambda function)

```js
const max = (a, b) => {
const sum = (a, b) => {
return a + b;
};
```

> Lambda expression

```js
const max = (a, b) => a + b;
const sum = (a, b) => a + b;
```

```js
const add = (a) => (b) => a + b;
const sum = (a) => (b) => a + b;

// prettier-ignore
const hash =
(data = {}) =>
(key, value) => ((data[key] = value), data);
(key, value) => ((data[key] = value), data);
```

> Superposition

```js
const expr2 = add(
const expr2 = sum(
pow(mul(5, 8), 2),
div(inc(sqrt(20)), log(2, 7))
);
Expand Down Expand Up @@ -87,10 +88,10 @@ const result = curry((a, b, c) => a + b + c)(1, 2)(3);
> Wrapper

```js
const add = (a, b) => a + b;
const sum = (a, b) => a + b;

console.log('Add numbers: 5 + 2 = ' + add(5, 2));
console.log('Add floats: 5.1 + 2.3 = ' + add(5.1, 2.3));
console.log(`Concatenate: '5' + '2' = '${add('5', '2')}'`);
console.log('Subtraction: 5 + (-2) = ' + add(5, -2));
console.log('Add numbers: 5 + 2 = ' + sum(5, 2));
console.log('Add floats: 5.1 + 2.3 = ' + sum(5.1, 2.3));
console.log(`Concatenate: '5' + '2' = '${sum('5', '2')}'`);
console.log('Subtraction: 5 + (-2) = ' + sum(5, -2));
```
7 changes: 5 additions & 2 deletions content/en/2-7-Closure.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ console.log(a);
> Callback

```js
const add = (a, b) => a + b;
// Return result
const sum = (a, b) => a + b;

// Pass result to a callback
const sum = (a, b, callback) => callback(a + b);
```

```js
console.log('add(5, 2) =', add(5, 2));
console.log('sum(5, 2) =', sum(5, 2));
sum(5, 2, console.log.bind(null, 'sum(5, 2) ='));
```

Expand Down
22 changes: 11 additions & 11 deletions content/ru/2-6-Function.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ function sum(a, b) {
Функциональное выражение с именованной функцией (Named function expression):

```js
const max = function max(a, b) {
const sum = function sum(a, b) {
return a + b;
};
```

Анонимное функциональное выражение (Anonymous function expression):

```js
const max = function (a, b) {
const sum = function (a, b) {
return a + b;
};
```

Стрелочная или лямбда-функция (Arrow, Lambda function):

```js
const max = (a, b) => {
const sum = (a, b) => {
return a + b;
};
```

Лямбда-выражение, Функция-стрелка с выражением в качестве тела (Lambda expression, Arrow function):

```js
const max = (a, b) => a + b;
const sum = (a, b) => a + b;
```

> Чистая функция (Pure Function) — детерминированная функция без побочных эффектов.
Expand All @@ -53,7 +53,7 @@ const max = (a, b) => a + b;
Примеры:

```js
const add = (a) => (b) => a + b;
const sum = (a) => (b) => a + b;

const hash =
(data = {}) =>
Expand All @@ -63,7 +63,7 @@ const hash =
> Суперпозиция (Superposition) — объединение вызова функций в выражения таким образом, что результат одних функций становится аргументами других функций.

```js
const expr2 = add(
const expr2 = sum(
pow(mul(5, 8), 2),
div(inc(sqrt(20)), log(2, 7))
);
Expand Down Expand Up @@ -109,10 +109,10 @@ const result = curry((a, b, c) => a + b + c)(1, 2)(3);
Функция, которая оборачивает другую функцию (иногда объект, интерфейс или функциональный объект), добавляя ему дополнительное поведение. Можно обернуть целый API интерфейс и даже асинхронную функцию вместе с колбеками (если известен контракт).

```js
const add = (a, b) => a + b;
const sum = (a, b) => a + b;

console.log(`Add nums: ${add(5, 2)}`);
console.log(`Add float: ${add(5.1, 2.3)}`);
console.log(`Concatenate: ${add('5', '2')}`);
console.log(`Subtraction: ${add(5, -2)}`);
console.log(`Add nums: ${sum(5, 2)}`);
console.log(`Add float: ${sum(5.1, 2.3)}`);
console.log(`Concatenate: ${sum('5', '2')}`);
console.log(`Subtraction: ${sum(5, -2)}`);
```
7 changes: 5 additions & 2 deletions content/ru/2-7-Closure.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,15 @@ console.log(a);
> Callback

```js
const add = (a, b) => a + b;
// Обычный возврат результата
const sum = (a, b) => a + b;

// Возврат результата в функцию обратного вызова
const sum = (a, b, callback) => callback(a + b);
```

```js
console.log('add(5, 2) =', add(5, 2));
console.log('sum(5, 2) =', sum(5, 2));
sum(5, 2, console.log.bind(null, 'sum(5, 2) ='));
```

Expand Down