Skip to content

Commit d30dccb

Browse files
committed
Added lambda equivalents
1 parent 3a33259 commit d30dccb

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

JavaScript/1-closure.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ const log = function(base, n) {
44
return Math.log(n) / Math.log(base);
55
};
66

7+
// const log = (base, n) => Math.log(n) / Math.log(base);
8+
79
function createLog(base) {
810
return function(n) {
911
return log(base, n);
1012
};
1113
}
1214

15+
// const createLog = (base) => (n) => log(base, n);
16+
1317
const lg = createLog(10);
1418
const ln = createLog(Math.E);

JavaScript/2-lambda.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ const log = function(base, n) {
44
return Math.log(n) / Math.log(base);
55
};
66

7+
// const log = (base, n) => Math.log(n) / Math.log(base);
8+
79
const lg = n => log(10, n);
810
const ln = n => log(Math.E, n);

JavaScript/3-bind.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ const log = function(base, n) {
44
return Math.log(n) / Math.log(base);
55
};
66

7+
// const log = (base, n) => Math.log(n) / Math.log(base);
8+
79
const lg = log.bind(null, 10);
810
const ln = log.bind(null, Math.E);

JavaScript/4-curry.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ const sum3 = function(a, b, c) {
44
return a + b + c;
55
};
66

7+
// const sum3 = (a, b, c) => (a + b + c);
8+
79
function curry(fn, x) {
810
return function(...args) {
9-
args.push(x);
10-
return fn(...args);
11+
return fn(x, ...args);
1112
};
1213
}
1314

15+
// const curry = (fn, x) => (...args) => fn(x, ...args);
16+
1417
const f1 = curry(sum3, 10);
1518
const f2 = curry(f1, 5);
1619
const y = f2(1);

0 commit comments

Comments
 (0)