diff --git a/Exercises/1-let.js b/Exercises/1-let.js index d705443..c321cb9 100644 --- a/Exercises/1-let.js +++ b/Exercises/1-let.js @@ -1,5 +1,5 @@ 'use strict'; -let name = undefined; +let name = 'Alexander'; module.exports = { name }; diff --git a/Exercises/2-const.js b/Exercises/2-const.js index 5512738..d424717 100644 --- a/Exercises/2-const.js +++ b/Exercises/2-const.js @@ -1,5 +1,5 @@ 'use strict'; -const year = undefined; +const year = 1997; module.exports = { year }; diff --git a/Exercises/3-hello.js b/Exercises/3-hello.js index a597391..19c0fc7 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..bb2f505 100644 --- a/Exercises/4-range.js +++ b/Exercises/4-range.js @@ -1,5 +1,17 @@ 'use strict'; -const range = null; +const range = (start, end) => { + const length = end - start; + + if (length < 0) return []; + const arr = []; + + for (let i = 0; i <= length; i++) { + arr[i] = start; + start++; + } + + return arr; +}; module.exports = { range }; diff --git a/Exercises/5-range-odd.js b/Exercises/5-range-odd.js index 54bb5b4..b8d9b40 100644 --- a/Exercises/5-range-odd.js +++ b/Exercises/5-range-odd.js @@ -1,5 +1,18 @@ 'use strict'; -const rangeOdd = null; +const rangeOdd = (start, end) => { + const length = end - start; + + if (length < 0) return []; + 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..37fa911 100644 --- a/Exercises/6-calculate.js +++ b/Exercises/6-calculate.js @@ -1,11 +1,20 @@ '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 MAX_ITERATION = 9; + const results = []; + + for (let i = 0; i <= MAX_ITERATION; i++) { + results.push(average(square(i), cube(i))); + } + + return results; +}; module.exports = { square, cube, average, calculate }; diff --git a/Exercises/7-objects.js b/Exercises/7-objects.js index 0920026..038a36e 100644 --- a/Exercises/7-objects.js +++ b/Exercises/7-objects.js @@ -1,5 +1,12 @@ 'use strict'; -const fn = null; +const fn = () => { + const person = { name: 'Alex' }; + // let secondPerson = { name: 'Boris' }; + const secondPerson = { name: 'Boris' }; + + person.name = 'Jake'; + secondPerson.name = 'Oleg'; +}; 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..af55841 100644 --- a/Exercises/9-array.js +++ b/Exercises/9-array.js @@ -1,7 +1,16 @@ 'use strict'; -const phonebook = null; +const phonebook = [ + { name: 'Alex', phone: '+79990259845' }, + { name: 'Boris', phone: '+79147255521' }, + { name: 'Jake', phone: '+79263042775' }, + { name: 'John', phone: '+79169023517' }, +]; -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..a82d1b5 100644 --- a/Exercises/a-hash.js +++ b/Exercises/a-hash.js @@ -1,7 +1,12 @@ 'use strict'; -const phonebook = null; +const phonebook = { + 'Alex': '+79990259845', + 'Boris': '+79147255521', + 'Jake': '+79263042775', + 'John': '+79169023517', +}; -const findPhoneByName = null; +const findPhoneByName = (name) => phonebook[name]; module.exports = { phonebook, findPhoneByName };