From b846fe48fe03f03bd325670949283edb416f1539 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 24 Oct 2019 10:43:08 +0300 Subject: [PATCH 1/2] Tasks 1-4 NonStudent User --- Exercises/1-random.js | 8 ++------ Exercises/2-key.js | 13 ++++++++----- Exercises/3-ip.js | 10 ++++------ Exercises/4-methods.js | 22 ++++++---------------- package.json | 2 +- 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/Exercises/1-random.js b/Exercises/1-random.js index ef5ccaf..4537023 100644 --- a/Exercises/1-random.js +++ b/Exercises/1-random.js @@ -1,9 +1,5 @@ 'use strict'; - -const random = (min, max) => { - // Generate random Number between from min to max - // Use Math.random() and Math.floor() - // See documentation at MDN -}; +// Tests not working (manual testing) +const random = (min, max) => min + Math.floor(Math.random() * (max - min + 1)); module.exports = { random }; diff --git a/Exercises/2-key.js b/Exercises/2-key.js index ba7e53a..0e7f0df 100644 --- a/Exercises/2-key.js +++ b/Exercises/2-key.js @@ -1,9 +1,12 @@ 'use strict'; - -const generateKey = (length, possible) => { - // Generate string of random characters - // Use Math.random() and Math.floor() - // See documentation at MDN +// Tests not working (manual testing) +const generateKey = (length, characters) => { + const randomChar = () => Math.floor(Math.random() * characters.length); + let randChar = ''; + for (let char = 1; char <= length; char++) { + randChar += characters[randomChar()]; + } + return randChar; }; module.exports = { generateKey }; diff --git a/Exercises/3-ip.js b/Exercises/3-ip.js index 5b448dd..c3111f5 100644 --- a/Exercises/3-ip.js +++ b/Exercises/3-ip.js @@ -1,11 +1,9 @@ 'use strict'; - +// Tests not working (manual testing) const ipToInt = (ip = '127.0.0.1') => { - // Parse ip address as string, for example '10.0.0.1' - // to ['10', '0', '0', '1'] to [10, 0, 0, 1] - // and convert to Number value 167772161 with sitwise shift - // (10 << 8 << 8 << 8) + (0 << 8 << 8) + (0 << 8) + 1 === 167772161 - // Use Array.prototype.reduce of for loop + const fn = (res, item) => (res << 8) + parseInt(item); + return ip.split('.').reduce(fn, 0); }; + module.exports = { ipToInt }; diff --git a/Exercises/4-methods.js b/Exercises/4-methods.js index c1038e8..ab9eb86 100644 --- a/Exercises/4-methods.js +++ b/Exercises/4-methods.js @@ -1,21 +1,11 @@ 'use strict'; - +// Tests not working (manual testing) const methods = iface => { - // Introspect all properties of iface object and - // extract function names and number of arguments - // For example: { - // m1: x => [x], - // m2: function (x, y) { - // return [x, y]; - // }, - // m3(x, y, z) { - // return [x, y, z]; - // } - // will return: [ - // ['m1', 1], - // ['m2', 2], - // ['m3', 3] - // ] + const array = []; + for (const i in iface) { + if (typeof iface[i] === 'function') array.push([i, iface[i].length]); + } + return array; }; module.exports = { methods }; diff --git a/package.json b/package.json index 4bf9ce8..7291c2c 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" }, "dependencies": { "eslint": "^6.4.0", From 7e1c8e56b17b0e734f6038dcc4398632f8b6c25b Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 24 Oct 2019 10:47:37 +0300 Subject: [PATCH 2/2] Delete package.json --- package.json | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 7291c2c..0000000 --- a/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "example", - "private": true, - "version": "1.0.1", - "author": "Timur Shemsedinov ", - "license": "MIT", - "scripts": { - "test": "eslint ./Exercises && hpw" - }, - "dependencies": { - "eslint": "^6.4.0", - "hpw": "^0.1.8" - } -}