Skip to content

Commit 252e1a0

Browse files
AntonovIgorkam4atka
authored andcommitted
Добавит исходники примеров
1 parent 1f51ef5 commit 252e1a0

File tree

314 files changed

+31861
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

314 files changed

+31861
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log(`Hello, world from Node ${process.version}`);

01-basic/04-hello-world/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Глава 1.4 Привет, Мир
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const utils = require(`./utils`);
4+
5+
const alphabet = [`А`, `B`, `C`, `D`, `E`, `F`, `G`];
6+
7+
// Тасование массива
8+
console.log(`Тасование массива:`);
9+
console.log(utils.shuffle(alphabet));
10+
11+
// Получение случайного числа
12+
console.log(`Получение случайного число от 1 до 10`);
13+
console.log(utils.getRandomInt(1, 10));
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
'use strict';
2+
3+
/**
4+
* Перетасовка массива по алгоритму
5+
* Фишера—Йетса.
6+
*
7+
* Функция возвращает новый массив
8+
*
9+
* @param {Array} array
10+
* @return {Array}
11+
*/
12+
const shuffle = (array) => {
13+
const resultArray = array.slice();
14+
for (let i = resultArray.length - 1; i > 0; i--) {
15+
const randomNumber = Math.floor(Math.random() * (i + 1));
16+
[resultArray[randomNumber], resultArray[i]] = [resultArray[i], resultArray[randomNumber]];
17+
}
18+
19+
return resultArray;
20+
};
21+
22+
/**
23+
* Возвращает случайное число в диапазоне
24+
* `min` и `max`.
25+
*
26+
* @param {Number} min
27+
* @param {Number} max
28+
* @return {Number}
29+
*/
30+
const getRandomInt = (min, max) => {
31+
min = Math.ceil(min);
32+
max = Math.floor(max);
33+
return Math.floor(Math.random() * (max - min + 1)) + min;
34+
};
35+
36+
module.exports = {
37+
getRandomInt,
38+
shuffle,
39+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
const simpleModule = require(`./simple-module`);
4+
5+
console.log(simpleModule);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
// Экспортируем myProperty со значением 1
4+
module.exports.myProperty = 1;
5+
6+
// Экспортируем фунцию foo
7+
module.exports.foo = () => console.log(`Hello from function`);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
exports.foo = () => console.log(`This is first function`);
4+
exports.anotherFoo = () => console.log(`This if second function`);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
const simpleModule = require(`./exports`);
4+
console.log(simpleModule);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
const simpleModule = require(`./simple-module`);
4+
5+
console.log(simpleModule);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
const foo = (text) => console.log(text);
4+
const anotherFoo = () => console.log(`This is another func`);
5+
6+
module.exports = {
7+
foo,
8+
};
9+
10+
exports.anotherFoo = anotherFoo;

0 commit comments

Comments
 (0)