From 02f5e35e6c374a5f6012af4e64c1fa49cdc53b99 Mon Sep 17 00:00:00 2001 From: Katywolk Date: Thu, 6 Feb 2025 13:17:13 +0800 Subject: [PATCH] Solving problems on the topic Closure --- Exercises/1-seq.js | 3 ++- Exercises/2-array.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Exercises/1-seq.js b/Exercises/1-seq.js index 0cc00a7..797aad7 100644 --- a/Exercises/1-seq.js +++ b/Exercises/1-seq.js @@ -1,5 +1,6 @@ 'use strict'; -const seq = (f) => (g) => (x) => 0; +const seq = (f) => (g) => (typeof g === 'number' ? f(g) : seq((x) => f(g(x)))); + module.exports = { seq }; diff --git a/Exercises/2-array.js b/Exercises/2-array.js index b6d47cf..a287457 100644 --- a/Exercises/2-array.js +++ b/Exercises/2-array.js @@ -1,5 +1,11 @@ 'use strict'; -const array = () => null; +const array = () => { + const arr = []; + const a = (index) => arr[index]; + a.push = (value) => arr.push(value); + a.pop = () => arr.pop(); + return a; +}; module.exports = { array };