Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Exercises/1-seq.js
Original file line number Diff line number Diff line change
@@ -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 };
22 changes: 21 additions & 1 deletion Exercises/2-array.js
Original file line number Diff line number Diff line change
@@ -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 };