From 4be553984a91817e7d7226788c7f3e536d611702 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 10 Aug 2020 16:44:13 +0300 Subject: [PATCH] LABS 1-9, a --- 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 | 15 +++++++++++---- Exercises/7-objects.js | 13 +++++++++++-- Exercises/8-create.js | 2 +- Exercises/9-array.js | 11 +++++++++-- Exercises/a-hash.js | 7 +++++-- 10 files changed, 56 insertions(+), 16 deletions(-) diff --git a/Exercises/1-let.js b/Exercises/1-let.js index d705443..ba58246 100644 --- a/Exercises/1-let.js +++ b/Exercises/1-let.js @@ -1,5 +1,5 @@ 'use strict'; -let name = undefined; +let name = 'Sasha'; module.exports = { name }; diff --git a/Exercises/2-const.js b/Exercises/2-const.js index 5512738..b6433ef 100644 --- a/Exercises/2-const.js +++ b/Exercises/2-const.js @@ -1,5 +1,5 @@ 'use strict'; -const year = undefined; +const year = 1983; module.exports = { year }; diff --git a/Exercises/3-hello.js b/Exercises/3-hello.js index a597391..369cf3a 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(`Hi ${name}!`); module.exports = { hello }; diff --git a/Exercises/4-range.js b/Exercises/4-range.js index 31bd852..48e7586 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 arr = []; + for (let i = start; i <= end; i++) { + arr.push(i); + } + return arr; +}; module.exports = { range }; diff --git a/Exercises/5-range-odd.js b/Exercises/5-range-odd.js index 54bb5b4..c275934 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 arr = []; + for (let i = start; i <= end; i++) { + if (i % 2 !== 0) { + arr.push(i); + } + } + return arr; +}; module.exports = { rangeOdd }; diff --git a/Exercises/6-calculate.js b/Exercises/6-calculate.js index dfecf6b..fdd875c 100644 --- a/Exercises/6-calculate.js +++ b/Exercises/6-calculate.js @@ -1,11 +1,18 @@ 'use strict'; -const square = null; +const square = x => x * x; -const cube = null; +const cube = x => x ** 3; -const average = null; +const average = (a, b) => (a + b) / 2; -const calculate = null; +const calculate = () => { + const arr = []; + for (let i = 0; i <= 9; i++) { + const av = average(square(i), cube(i)); + arr.push(av); + } + return arr; +}; module.exports = { square, cube, average, calculate }; diff --git a/Exercises/7-objects.js b/Exercises/7-objects.js index 0920026..8488b58 100644 --- a/Exercises/7-objects.js +++ b/Exercises/7-objects.js @@ -1,5 +1,14 @@ 'use strict'; -const fn = null; - +const fn = () => { + const objOne = { name: 'One' }; + let objTwo = { name: 'Two' }; + objOne.name = 'something'; + objTwo.name = 'something too'; + //objOne = {other: 3} ; + objTwo = { otherTwo: 2 }; + /*objOne - const => другой объект присвоить нельзя, + изменять поля можно у обоих объектов*/ +}; +fn(); 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..315d269 100644 --- a/Exercises/9-array.js +++ b/Exercises/9-array.js @@ -1,7 +1,14 @@ 'use strict'; -const phonebook = null; +const phonebook = [ + { name: 'Marcus', phone: '+380445554433' }, + { name: 'Vasya', phone: '+38454545454' }, +]; -const findPhoneByName = null; +const findPhoneByName = name => { + for (const rec of phonebook) { + if (rec.name === name) return rec.phone; + } +}; module.exports = { phonebook, findPhoneByName }; diff --git a/Exercises/a-hash.js b/Exercises/a-hash.js index 466c69a..8898ed4 100644 --- a/Exercises/a-hash.js +++ b/Exercises/a-hash.js @@ -1,7 +1,10 @@ 'use strict'; -const phonebook = null; +const phonebook = { + Marcus: '+380445554433', + Vasya: '+38454545454', +}; -const findPhoneByName = null; +const findPhoneByName = name => phonebook[name]; module.exports = { phonebook, findPhoneByName };