From ffd38f117788ffa8a2c52956bbf7d0ba589ac66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A7=D1=83=D0=B1=D0=BA=D0=BE=20=D0=9C=D0=B8=D1=85=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=BE?= Date: Sun, 3 Dec 2023 22:00:02 +0200 Subject: [PATCH] Ik-12 Chubko All labworks from 1 to 2 --- Exercises/1-seq.js | 10 ++++++++-- Exercises/2-array.js | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Exercises/1-seq.js b/Exercises/1-seq.js index 0cc00a7..be4d843 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) => (arg) => { + if (typeof arg === 'number') { + return f(arg); + } else { + return seq((x) => f(arg(x))); + } + }; + module.exports = { seq }; diff --git a/Exercises/2-array.js b/Exercises/2-array.js index b6d47cf..8be8e87 100644 --- a/Exercises/2-array.js +++ b/Exercises/2-array.js @@ -1,5 +1,25 @@ 'use strict'; -const array = () => null; +const array = () => { + const data = []; + + return (arg) => { + if (typeof arg === 'number') { + return data[arg]; + } + + const method = arg.method; + const value = arg.value; + + if (method === 'push') { + data.push(value); + return; + } + + if (method === 'pop') { + return data.pop(); + } + }; + }; module.exports = { array };