From f252ff9d7539f87e3e21da402a43fef40d65cfb2 Mon Sep 17 00:00:00 2001 From: Olexandr Gorkavenko Date: Fri, 18 May 2018 00:11:38 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=20index.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson-6/index.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 lesson-6/index.html diff --git a/lesson-6/index.html b/lesson-6/index.html new file mode 100644 index 0000000..7250cd3 --- /dev/null +++ b/lesson-6/index.html @@ -0,0 +1,13 @@ + + + + + JS-courses + + +

lesson 6

+ + + + + \ No newline at end of file From 089668c78d4231d8fae373e24c5b088c9e6bf3c7 Mon Sep 17 00:00:00 2001 From: Olexandr Gorkavenko Date: Fri, 18 May 2018 00:12:04 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=20task1.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson-6/JS/task1.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lesson-6/JS/task1.js diff --git a/lesson-6/JS/task1.js b/lesson-6/JS/task1.js new file mode 100644 index 0000000..fc5bf8c --- /dev/null +++ b/lesson-6/JS/task1.js @@ -0,0 +1,25 @@ +/* +* Задание 1 +* Реализовать функцию, которая суммирует аргументы. +* +* function sum(x) { +* ... +* } +* +* sum(1)(2)(3) === 6 +*/ + +function sum(firstarg) { + + let curry = (nextarg) => { + firstarg += nextarg; + return curry; + } + + curry.toString = () => firstarg; + + return curry; +} + +console.log('Задание 1'); +console.log( sum(1)(2)(3) ); \ No newline at end of file From c8b6ca1a0263c85fc479add86a924ba97ec6ccc1 Mon Sep 17 00:00:00 2001 From: Olexandr Gorkavenko Date: Fri, 18 May 2018 00:12:28 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=20task2.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson-6/JS/task2.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lesson-6/JS/task2.js diff --git a/lesson-6/JS/task2.js b/lesson-6/JS/task2.js new file mode 100644 index 0000000..0b225bd --- /dev/null +++ b/lesson-6/JS/task2.js @@ -0,0 +1,32 @@ +/* +* Задание 2 +* Реализовать функцию, которая суммирует аргументы, если аргумент не передан - вернуть сумму. +* +* function sum(x) { +* ... +* } +* +* sum(1)(2)(3)...(N)() === сумме всех чисел до N +* +* +* Реализовать эту же функцию, только с возможностью получения значения без дополнительного пустого вызова. +* +* alert(sum(1)(2)(3)...(N)) +*/ + +// Задание 2.1 +function sum(arg) { + return nextArg => nextArg ? sum(arg + nextArg) : arg; +} + +console.log('\nЗадание 2.1'); +console.log( sum(1)(2)(3)(4)(5)(6)() ); + +// Задание 2.2 +function sumWOEmpty(arg) { + const add = nextArg => sumWOEmpty(arg + nextArg); + add.toString = () => arg; + return add; +} + +alert(sumWOEmpty(1)(2)(3)(4)(5)(6)); \ No newline at end of file From f0b8b10265d81022c7a0291723aefb1ec1b1076a Mon Sep 17 00:00:00 2001 From: Olexandr Gorkavenko Date: Fri, 18 May 2018 00:12:43 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=20task3.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson-6/JS/task3.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lesson-6/JS/task3.js diff --git a/lesson-6/JS/task3.js b/lesson-6/JS/task3.js new file mode 100644 index 0000000..f26c943 --- /dev/null +++ b/lesson-6/JS/task3.js @@ -0,0 +1,38 @@ +/* +* Задание 3 +* Реализовать счетчик который при вызове должен возвращать число на 1 больше, +* также иметь методы set и reset, работать это должно следующим образом. +* +* const counter = makeCounter(); +* counter() // 1 +* counter() // 2 +* counter.set(12); +* counter() // 12 +* counter.reset(); +* counter() // 1 +*/ + +function makeCounter() { + let initialValue = 0; + + const counter = () => ++initialValue; + + counter.set = (value) => { + initialValue = --value; + }; + + counter.reset = () => { + initialValue = 0; + }; + + return counter; +} + +console.log('\nЗадание 3'); +const counter = makeCounter(); +console.log(counter()); // 1 +console.log(counter()); // 2 +counter.set(12); +console.log(counter()); // 12 +counter.reset(); +console.log(counter()); // 1 \ No newline at end of file