From 52d1d4ee790619e6c8d16debe611e912de5a55fe Mon Sep 17 00:00:00 2001 From: Daniil Denisyuk Date: Thu, 19 Dec 2019 08:04:39 +0200 Subject: [PATCH 1/2] tasks --- Exercises/1-seq.js | 6 +++++- Exercises/2-array.js | 23 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Exercises/1-seq.js b/Exercises/1-seq.js index bdf0fe8..a4355ad 100644 --- a/Exercises/1-seq.js +++ b/Exercises/1-seq.js @@ -1,5 +1,9 @@ '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..8236422 100644 --- a/Exercises/2-array.js +++ b/Exercises/2-array.js @@ -1,5 +1,26 @@ 'use strict'; -const array = () => null; +const array = () => { + const arr = []; + const f = i => arr[i]; + f.push = value => Array.prototype.push.call(arr, value); + f.pop = () => Array.prototype.pop.call(arr); + return f; +}; + + +const arr = array(); + +arr.push('first'); +arr.push('second'); +arr.push('third'); +console.log(arr(0)); // Выводит: first +console.log(arr(1)); // Выводит: second +console.log(arr(2)); // Выводит: third +console.log(arr.pop()); // Выводит: third +console.log(arr.pop()); // Выводит: second +console.log(arr.pop()); // Выводит: first + +console.log(arr.pop()); module.exports = { array }; From 7248285e78ebd65ab352e5005c832c6a2e9520ec Mon Sep 17 00:00:00 2001 From: Daniil Denisyuk Date: Thu, 19 Dec 2019 08:08:50 +0200 Subject: [PATCH 2/2] tasks --- Exercises/2-array.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/Exercises/2-array.js b/Exercises/2-array.js index 8236422..484f359 100644 --- a/Exercises/2-array.js +++ b/Exercises/2-array.js @@ -8,19 +8,4 @@ const array = () => { return f; }; - -const arr = array(); - -arr.push('first'); -arr.push('second'); -arr.push('third'); -console.log(arr(0)); // Выводит: first -console.log(arr(1)); // Выводит: second -console.log(arr(2)); // Выводит: third -console.log(arr.pop()); // Выводит: third -console.log(arr.pop()); // Выводит: second -console.log(arr.pop()); // Выводит: first - -console.log(arr.pop()); - module.exports = { array };