Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
haigeno1 committed Jun 24, 2022
1 parent fedd59e commit 6fd1569
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ plugins/
webpack.config.dump.js
tmp/
*todo*
test.js
临时暂存待办.md
File renamed without changes.
27 changes: 27 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


function compose(...fns) {
var start = fns.length - 1;
return function () {
var i = start;
var result = fns[start].apply(this, arguments);
while (i--) result = fns[i].call(this, result);
return result;
};
}

// const _pipe = (f, g) => (...args) => g.call(null, f.apply(null, args))
// const compose = (...fns) => fns.reverse().reduce(_pipe)


// const _pipe = (f, g) => (...args) => g(f(...args))
// const compose = (...fns) => fns.reverse().reduce(_pipe)


// test
function f1(a, b) { return a + b }
function f2(a) { return 2 * a }
function f3(a) { return a * a }
// let f = compose(f1, f2, f3)
let f = compose(f3, f2, f1)
console.log(f(1, 2)) // 36
27 changes: 27 additions & 0 deletions test1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


function compose(...fns) {
var start = fns.length - 1;
return function () {
var i = start;
var result = fns[start].apply(this, arguments);
while (i--) result = fns[i].call(this, result);
return result;
};
}

// const _pipe = (f, g) => (...args) => g.call(null, f.apply(null, args))
// const compose = (...fns) => fns.reverse().reduce(_pipe)


// const _pipe = (f, g) => (...args) => g(f(...args))
// const compose = (...fns) => fns.reverse().reduce(_pipe)


// test
function f1(a, b) { return a + b }
function f2(a) { return 2 * a }
function f3(a) { return a * a }
// let f = compose(f1, f2, f3)
let f = compose(f3, f2, f1)
console.log(f(1, 2)) // 36
Empty file removed test5.js
Empty file.

0 comments on commit 6fd1569

Please sign in to comment.