From 2ee76ceae2cb05b6103773b52c8af19fdefd82fb Mon Sep 17 00:00:00 2001 From: andvseti Date: Sun, 9 Jan 2022 13:30:34 +0200 Subject: [PATCH] Quest completed --- 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 | 8 +++++++- Exercises/6-calculate.js | 14 ++++++++++---- Exercises/7-objects.js | 12 +++++++++++- Exercises/8-create.js | 2 +- Exercises/9-array.js | 11 +++++++++-- Exercises/a-hash.js | 8 ++++++-- 10 files changed, 54 insertions(+), 15 deletions(-) diff --git a/Exercises/1-let.js b/Exercises/1-let.js index d705443..aee6cc8 100644 --- a/Exercises/1-let.js +++ b/Exercises/1-let.js @@ -1,5 +1,5 @@ 'use strict'; -let name = undefined; +let name = 'andvs'; module.exports = { name }; diff --git a/Exercises/2-const.js b/Exercises/2-const.js index 5512738..9ea5205 100644 --- a/Exercises/2-const.js +++ b/Exercises/2-const.js @@ -1,5 +1,5 @@ 'use strict'; -const year = undefined; +const year = 1991; module.exports = { year }; diff --git a/Exercises/3-hello.js b/Exercises/3-hello.js index a597391..d5721c5 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(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..f1c4dc9 100644 --- a/Exercises/5-range-odd.js +++ b/Exercises/5-range-odd.js @@ -1,5 +1,11 @@ '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..f7239c3 100644 --- a/Exercises/6-calculate.js +++ b/Exercises/6-calculate.js @@ -1,11 +1,17 @@ '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 index = 0; index <= 9; index++) { + arr.push(average(square(index), cube(index))); + } + return arr; +}; module.exports = { square, cube, average, calculate }; diff --git a/Exercises/7-objects.js b/Exercises/7-objects.js index 0920026..435c7bf 100644 --- a/Exercises/7-objects.js +++ b/Exercises/7-objects.js @@ -1,5 +1,15 @@ 'use strict'; -const fn = null; +const fn = () => { + let obj = { name: '' }; + const obj1 = { name: '' }; + obj1.name = 'Andrei'; + console.dir(obj1); + obj = obj1; + console.dir(obj); + obj.name = 'Marcus'; + console.dir(obj1); + console.dir(obj); +}; 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..98f908c 100644 --- a/Exercises/9-array.js +++ b/Exercises/9-array.js @@ -1,7 +1,14 @@ 'use strict'; -const phonebook = null; +const phonebook = [ + { name: 'Marcus Aurelius', phone: '+380445554433' }, + { name: 'Andrei Shneyer', phone: '+380979707970' } +]; -const findPhoneByName = null; +const findPhoneByName = (name) => { + for (const obj of phonebook) { + if (obj.name === name) return obj.phone; + } +}; module.exports = { phonebook, findPhoneByName }; diff --git a/Exercises/a-hash.js b/Exercises/a-hash.js index 466c69a..9d29ede 100644 --- a/Exercises/a-hash.js +++ b/Exercises/a-hash.js @@ -1,7 +1,11 @@ 'use strict'; -const phonebook = null; +const phonebook = + { + 'Marcus Aurelius': '+380445554433', + 'Andrei Shneyer': '+380979707970' + }; -const findPhoneByName = null; +const findPhoneByName = (name) => phonebook[name]; module.exports = { phonebook, findPhoneByName };