From d9f46e6103434efedd680fe055d9c1fb234f0768 Mon Sep 17 00:00:00 2001 From: Konstantin Gorshkov Date: Sun, 20 Oct 2019 23:44:02 +0600 Subject: [PATCH 1/2] Implement function `seq` --- Exercises/sequential.js | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Exercises/sequential.js b/Exercises/sequential.js index bdf0fe8..900daa9 100644 --- a/Exercises/sequential.js +++ b/Exercises/sequential.js @@ -1,5 +1,8 @@ 'use strict'; -const seq = f => g => x => 0; +const seq = f => g => { + if (typeof(g) === 'function') return seq(a => f(g(a))); + return f(g); +}; module.exports = { seq }; diff --git a/package.json b/package.json index 9a553e8..b97ec94 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 a8a54cb5c103166017731b23dd59a9a19f7457ba Mon Sep 17 00:00:00 2001 From: Konstantin Gorshkov Date: Sat, 26 Oct 2019 15:58:52 +0600 Subject: [PATCH 2/2] Fixed: - Using ternary operator instead `if` condition - package.json file restored to their original state --- Exercises/sequential.js | 5 +---- package.json | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Exercises/sequential.js b/Exercises/sequential.js index 900daa9..d3f32e2 100644 --- a/Exercises/sequential.js +++ b/Exercises/sequential.js @@ -1,8 +1,5 @@ 'use strict'; -const seq = f => g => { - if (typeof(g) === 'function') return seq(a => f(g(a))); - return f(g); -}; +const seq = f => g => (typeof(g) === 'function' ? seq(a => f(g(a))) : f(g)); module.exports = { seq }; diff --git a/package.json b/package.json index b97ec94..9a553e8 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",