From 204a475a9e71826240b53ba69671d5d5ed9f8f02 Mon Sep 17 00:00:00 2001 From: Alym Aleksey | work Date: Thu, 10 Dec 2020 21:17:18 +0300 Subject: [PATCH] All tasks --- Exercises/1-let.js | 2 +- Exercises/2-const.js | 2 +- Exercises/3-hello.js | 2 +- Exercises/4-range.js | 8 +++++++- Exercises/5-range-odd.js | 10 +++++++++- Exercises/6-calculate.js | 16 ++++++++++++---- Exercises/7-objects.js | 11 ++++++++++- Exercises/8-create.js | 2 +- Exercises/9-array.js | 11 +++++++++-- Exercises/a-hash.js | 7 +++++-- 10 files changed, 56 insertions(+), 15 deletions(-) diff --git a/Exercises/1-let.js b/Exercises/1-let.js index d705443..a3c59bf 100644 --- a/Exercises/1-let.js +++ b/Exercises/1-let.js @@ -1,5 +1,5 @@ 'use strict'; -let name = undefined; +let name = 'Aleksey'; module.exports = { name }; diff --git a/Exercises/2-const.js b/Exercises/2-const.js index 5512738..465e192 100644 --- a/Exercises/2-const.js +++ b/Exercises/2-const.js @@ -1,5 +1,5 @@ 'use strict'; -const year = undefined; +const year = 1988; module.exports = { year }; diff --git a/Exercises/3-hello.js b/Exercises/3-hello.js index a597391..f36ff5f 100644 --- a/Exercises/3-hello.js +++ b/Exercises/3-hello.js @@ -1,5 +1,5 @@ 'use strict'; -const hello = null; +const hello = name => console.log(`Hello, ${name}`); module.exports = { hello }; diff --git a/Exercises/4-range.js b/Exercises/4-range.js index 31bd852..3c7e344 100644 --- a/Exercises/4-range.js +++ b/Exercises/4-range.js @@ -1,5 +1,11 @@ 'use strict'; -const range = null; +const range = (start, end) => { + const res = []; + for (let i = start; i <= end; i += 1) { + res.push(i); + } + return res; +}; module.exports = { range }; diff --git a/Exercises/5-range-odd.js b/Exercises/5-range-odd.js index 54bb5b4..2e69e3a 100644 --- a/Exercises/5-range-odd.js +++ b/Exercises/5-range-odd.js @@ -1,5 +1,13 @@ 'use strict'; -const rangeOdd = null; +const rangeOdd = (start, end) => { + const res = []; + + for (let i = start; i <= end; i += 1) { + if (i % 2) res.push(i); + } + + return res; +}; module.exports = { rangeOdd }; diff --git a/Exercises/6-calculate.js b/Exercises/6-calculate.js index dfecf6b..31ab208 100644 --- a/Exercises/6-calculate.js +++ b/Exercises/6-calculate.js @@ -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 = null; +const calculate = () => { + const res = []; + + for (let i = 0; i < 10; i += 1) { + res.push(average(square(i), cube(i))); + } + + return res; +}; module.exports = { square, cube, average, calculate }; diff --git a/Exercises/7-objects.js b/Exercises/7-objects.js index 0920026..205806c 100644 --- a/Exercises/7-objects.js +++ b/Exercises/7-objects.js @@ -1,5 +1,14 @@ 'use strict'; -const fn = null; +const fn = () => { + let obj = { name: 'name' }; + const obj2 = { name: 'name' }; + + obj.name = 'pavel'; + obj2.name = 'pavel'; + + const obj3 = { name: 'Sergey' }; + obj = obj3; +}; module.exports = { fn }; diff --git a/Exercises/8-create.js b/Exercises/8-create.js index ac27ddd..f400582 100644 --- a/Exercises/8-create.js +++ b/Exercises/8-create.js @@ -1,5 +1,5 @@ 'use strict'; -const createUser = null; +const createUser = (name, city) => ({ name, city }); module.exports = { createUser }; diff --git a/Exercises/9-array.js b/Exercises/9-array.js index 466c69a..e4a861d 100644 --- a/Exercises/9-array.js +++ b/Exercises/9-array.js @@ -1,7 +1,14 @@ 'use strict'; -const phonebook = null; +const phonebook = [ + { name: 'Aleksey', phone: '1234567890' }, + { name: 'Pavel', phone: '0987654321' }, +]; -const findPhoneByName = null; +const findPhoneByName = name => { + for (const p of phonebook) { + return p.name === name ? p.phone : null; + } +}; module.exports = { phonebook, findPhoneByName }; diff --git a/Exercises/a-hash.js b/Exercises/a-hash.js index 466c69a..2738bf9 100644 --- a/Exercises/a-hash.js +++ b/Exercises/a-hash.js @@ -1,7 +1,10 @@ 'use strict'; -const phonebook = null; +const phonebook = { + Aleksey: '1234567890', + Pavel: '0987654321' +}; -const findPhoneByName = null; +const findPhoneByName = name => phonebook[name]; module.exports = { phonebook, findPhoneByName };