Skip to content
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

lab tasks 1, 2, 3, 4, 5, 6, 7, 8, 9, a #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Exercises.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
отдает массив нечетных чисел из диапазона [15, 30] включая крайние числа.

## Функции

~~~~
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you committing changes to readme?

6. Вложенные вызовы функций в цикле
- Реализуйте функцию `average` с сигнатурой
`average(a: number, b: number): number` вычисляющую среднее арифметическое своих
Expand Down
6 changes: 4 additions & 2 deletions Exercises/1-let.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';
//
let name = 'Don Kihot';
//
module.exports = { name };

let name = undefined;

module.exports = { name };
2 changes: 1 addition & 1 deletion Exercises/2-const.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

const year = undefined;
const year = 1917;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

64908rm_25_954


module.exports = { year };
2 changes: 1 addition & 1 deletion Exercises/3-hello.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

const hello = null;
const hello = name => console.log(`Hello, ${name}!`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const hello = name => console.log(`Hello, ${name}!`);
const hello = name => {
console.log(`Hello, ${name}!`);
};

We use single line functions when outer function need to return value of internal call.


module.exports = { hello };
15 changes: 14 additions & 1 deletion Exercises/4-range.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
'use strict';

const range = null;

const range = (start, end) => {
const arr = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may allocate array with final length. See solution: https://github.com/HowProgrammingWorks/Reusable/blob/master/Solutions/4-range.js

const length = end - start;

for (let i = 0; i <= length; i++) {
arr[i] = start;
start++;
}

return arr;
};



module.exports = { range };
13 changes: 12 additions & 1 deletion Exercises/5-range-odd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
'use strict';

const rangeOdd = null;
const rangeOdd = (begin, end) => {
const len = Math.ceil((end - begin) / 2);
if (len < 0) return [];
const array = new Array(len);
let i = 0;
for (let n = begin; n <= end; n++) {
if (n % 2 !== 0) array[i++] = n;
}
return array;
};


module.exports = { rangeOdd };

16 changes: 12 additions & 4 deletions Exercises/6-calculate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
'use strict';

const square = null;
const square = n => n * n;

const cube = null;
const cube = n => n ** 3;

const average = null;
const average = (a, b) => (a + b) / 2;

const calculate = () => {
const arr = [];
for (let i = 0; i <= 9; i++) {
const calc = average(square(i), cube(i));
arr.push(calc);
}
return arr;
};

const calculate = null;

module.exports = { square, cube, average, calculate };
12 changes: 11 additions & 1 deletion Exercises/7-objects.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
'use strict';

const fn = null;
const fn = () => {
const name1 = { name: 'John' };
let name2 = { name: 'John' };

name1.name = 'Dou';
name2.name = 'Dou';

name2 = { name: 'John Dou' };
};



module.exports = { fn };
5 changes: 4 additions & 1 deletion Exercises/8-create.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict';

const createUser = null;
const createUser = (name, city) => ({ name, city });

console.log(createUser('John Dou', 'Rome'));


module.exports = { createUser };
10 changes: 8 additions & 2 deletions Exercises/9-array.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
'use strict';

const phonebook = null;
const phonebook = [
{ name: 'Marcus Aurelius', phone: '+380445554-433' },
{ name: 'Mao Zedong', phone: '+380445554-722' },
{ name: 'Rene Descartes', phone: '+380445554-988' },
];

const findPhoneByName = null;
const findPhoneByName = name => {
for (const number of phonebook) number.name === name ? number.phone : null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will return undefined.

};

module.exports = { phonebook, findPhoneByName };
8 changes: 6 additions & 2 deletions Exercises/a-hash.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

const phonebook = null;
const phonebook = {
MarcusAurelius: { phone: '+380445554-433' },
MaoZedong: { phone: '+380445554-722' },
ReneDescartes: { phone: '+380445554-988' },
};

const findPhoneByName = null;
const findPhoneByName = name => phonebook[name];

module.exports = { phonebook, findPhoneByName };
5 changes: 0 additions & 5 deletions Solutions/1-let.js

This file was deleted.

5 changes: 0 additions & 5 deletions Solutions/2-const.js

This file was deleted.

7 changes: 0 additions & 7 deletions Solutions/3-hello.js

This file was deleted.

14 changes: 0 additions & 14 deletions Solutions/4-range.js

This file was deleted.

14 changes: 0 additions & 14 deletions Solutions/5-range-odd.js

This file was deleted.

18 changes: 0 additions & 18 deletions Solutions/6-calculate.js

This file was deleted.

13 changes: 0 additions & 13 deletions Solutions/7-objects.js

This file was deleted.

5 changes: 0 additions & 5 deletions Solutions/8-create.js

This file was deleted.

14 changes: 0 additions & 14 deletions Solutions/9-array.js

This file was deleted.

10 changes: 0 additions & 10 deletions Solutions/a-hash.js

This file was deleted.