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 };