From a511d9534a9c98f8fe3e17da062972b2949e6f31 Mon Sep 17 00:00:00 2001 From: Jhon Mosk Date: Fri, 14 Jul 2023 14:49:45 +0300 Subject: [PATCH] Lab work is ready --- Exercises/.prettierrc | 7 +++++++ Exercises/1-seq.js | 8 +++++++- Exercises/2-array.js | 10 +++++++++- JavaScript/2-chain.js | 13 ++++--------- package.json | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 Exercises/.prettierrc diff --git a/Exercises/.prettierrc b/Exercises/.prettierrc new file mode 100644 index 0000000..4cb85b8 --- /dev/null +++ b/Exercises/.prettierrc @@ -0,0 +1,7 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "semi": true, + "singleQuote": true, + "space-before-function-paren": ["error", "never"] +} diff --git a/Exercises/1-seq.js b/Exercises/1-seq.js index 0cc00a7..3f27dd6 100644 --- a/Exercises/1-seq.js +++ b/Exercises/1-seq.js @@ -1,5 +1,11 @@ 'use strict'; -const seq = (f) => (g) => (x) => 0; +const seq = (f) => (g) => { + if (typeof g === 'number') { + return f(g); + } + + return seq((x) => f(g(x))); +}; module.exports = { seq }; diff --git a/Exercises/2-array.js b/Exercises/2-array.js index b6d47cf..cf26fe5 100644 --- a/Exercises/2-array.js +++ b/Exercises/2-array.js @@ -1,5 +1,13 @@ 'use strict'; -const array = () => null; +const array = () => { + const data = []; + const obj = (index) => data[index]; + + obj.push = (value) => data.push(value); + obj.pop = () => data.pop(); + + return obj; +}; module.exports = { array }; diff --git a/JavaScript/2-chain.js b/JavaScript/2-chain.js index 1bf2a6b..0969661 100644 --- a/JavaScript/2-chain.js +++ b/JavaScript/2-chain.js @@ -1,22 +1,17 @@ -'use strict'; +"use strict"; const hash = () => { const data = {}; - Object.defineProperty(data, 'add', { + Object.defineProperty(data, "add", { enumerable: false, value(key, value) { data[key] = value; return data; - } + }, }); return data; }; // Usage -console.dir( - hash() - .add('name', 'Marcus') - .add('city', 'Roma') - .add('born', 121) -); +console.dir(hash().add("name", "Marcus").add("city", "Roma").add("born", 121)); diff --git a/package.json b/package.json index ebfc0c9..c4de81a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Timur Shemsedinov ", "license": "MIT", "scripts": { - "test": "eslint ./Exercises; hpw", + "test": "eslint ./Exercises && hpw", "ci": "eslint ./Exercises && hpw" }, "dependencies": {